Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Thrift:在列表定义中使用外部java类_Java_Thrift_Thrift Protocol - Fatal编程技术网

Thrift:在列表定义中使用外部java类

Thrift:在列表定义中使用外部java类,java,thrift,thrift-protocol,Java,Thrift,Thrift Protocol,我是节俭的新手,如果能在编写节俭生成器文件时得到一些帮助,我将不胜感激。我想使用一个Java服务器,它有许多不同语言的客户端。我正在使用Thrift自动生成这些文件 这是我的旧档案: namespace php example namespace py example namespace csharp example namespace cpp example namespace perl example namespace d example namespace java javaobject

我是节俭的新手,如果能在编写节俭生成器文件时得到一些帮助,我将不胜感激。我想使用一个Java服务器,它有许多不同语言的客户端。我正在使用Thrift自动生成这些文件

这是我的旧档案:

namespace php example
namespace py example
namespace csharp example
namespace cpp example
namespace perl example
namespace d example
namespace java javaobjectmethods

struct ExternalLibraryItem {
    1: required string name
}

service ExampleService {
    list<ExternalLibraryItem> javaObjectMethod(1:i32 count)
}
如果没有这一行,它当前将不允许我生成服务器文件

这是我的Java文件:

package javaobjectmethods;

import externalLibrary.ExternalLibaryItem;
import externalLibrary.ExternalLibraryClass;

public class javaObject {
    private String file;

    public javaObject(String file) {
        this.file = file;
    }

    public List<ExternalLibraryItem> javaObjectMethod(int count) {
        // this method returns List<ExternalLibraryItem>
        return ExternalLibraryClass.doThis(count, this.file);
    }
}
封装javaobjectmethods;
导入externalLibrary.ExternalLibaryItem;
导入externalLibrary.ExternalLibraryClass;
公共类javaObject{
私有字符串文件;
公共javaObject(字符串文件){
this.file=文件;
}
公共列表javaObjectMethod(int计数){
//此方法返回列表
返回ExternalLibraryClass.doThis(count,this.file);
}
}

简短回答:你不能。

所有Thrift
structs
都应该由代码生成。对于某些语言,创建了部分类(例如C#),这些类在这种情况下有帮助,但不是所有语言都有帮助。此外,在某些情况下(C++),基类可以在某种程度上进行自定义。对于Java来说

struct Foo {
  1: i32 bar
}
结果在一个以

public class foo implements org.apache.thrift.TBase<foo, foo._Fields>, 
                            java.io.Serializable, 
                            Cloneable, 
                            Comparable<foo>
公共类foo实现org.apache.thrift.TBase,
java.io.Serializable,
可克隆,
可比较的
这是周围规范和结构所需要和期望的

对于您的特定情况,一个可能的解决方案是将内部类转换为节约类,反之亦然


当然,如果您有更好的解决方法,我们将提供高质量的补丁。

非常好,谢谢。我想我可以解决这个问题,只是想看看不实施解决方案是否可行。
public class foo implements org.apache.thrift.TBase<foo, foo._Fields>, 
                            java.io.Serializable, 
                            Cloneable, 
                            Comparable<foo>