我正在尝试为私有(private)双变量创建一个 get 方法。
当我写作时
public class {
private double x = 4.12;
public int get(){
double temp = new Double(this.x);
return temp.intValue();
}
}
IDE 建议删除 Double 不必要的装箱“new Double(this.x)”
,并且它无法识别 intValue() 方法。只写时也是如此:
return this.x.intValue();
最佳答案
基元没有方法,并且创建 Double
的新实例只是为了立即再次解开它是没有意义的。
改为转换:
return (int) this.x;
关于java - 无法解析方法 'intValue()',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61064446/