在另一个Bruce Eckel练习中,我编写的代码采用了一种方法并在另一个类中更改了值.这是我的代码:
class Big {
float b;
}
public class PassObject {
static void f(Letter y) {
y.c = 'z';
} //end f()
static void g(Big z) {
z.b = 2.2;
}
public static void main(String[] args ) {
Big t = new Big();
t.b = 5.6;
System.out.println("1: t.b : " + t.b);
g(x);
System.out.println("2: t.b: " + t.b);
} //end main
}//end class
Run Code Online (Sandbox Code Playgroud)
它抛出的错误是"可能会损失精确度".
PassObject.java:13: possible loss of precision
found: double
required : float z.b = 2.2
passobject.java:20: possible …Run Code Online (Sandbox Code Playgroud)