我写了一个java类:
public class Tuple<X, Y> {
public final X x;
public final Y y;
public Tuple(X x, Y y) {
this.x = x;
this.y = y;
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我创建这样的函数时:
public Tuple<boolean, String> getResult()
{
try {
if(something.equals(something2))
return new Tuple(true, null);
}
catch (Exception e){
return new Tuple(false, e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)
但是,我收到以下编译错误:
unexpected type
required: reference
found: boolean
Run Code Online (Sandbox Code Playgroud)
我可以做什么?
Lui*_*oza 12
泛型不适用于原始类型.用Boolean而不是boolean.
public Tuple<Boolean, String> getResult() {
//your code goes here...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4528 次 |
| 最近记录: |