Can someone explain me this result?
Well this is my code:
public class foo <T> {
public static void main(String[] args) {
foo Foo = new foo();
System.out.println(Foo.compare(100L, 100));
System.out.println(Foo.compare(100L, 100L));
System.out.println(Foo.compare(127L, 127L));
System.out.println(Foo.compare(128L, 128L));
System.out.println();
System.out.println(System.getProperty("java.vendor"));
System.out.println(System.getProperty("java.version"));
}
public boolean compare( T val1, T val2) {
return ( val1 == val2 ) ? true : false;
}
}
and the result was:
false
true
true
false
Sun Microsystems Inc.
1.6.0_26
First of all:
It is strange because i have declared only one template class "T". The first comparison end up false because val1 is long and val2 is int (i had checked it through debuger). But it should not be, cos i have declared only one template class and same for both.
and
Second of all:
why every "long" larger numbers greater then 127 are not equal ??
Thanks!