Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The == operator

 
Per Radfe
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.util.ArrayList;
import java.util.Vector;
class Main extends Thread{
public static void main(String[] args) {

Vector<Integer> x = new Vector<Integer>();
ArrayList<Double> y = new ArrayList<Double>();

if ( x == y){
System.out.println("test");
}
}
}

This code dose´┐Żnt compile. I thought that you could compare any reference variable but obviously not? Is the == operator working like instanceof wich only can compare instances of the same class hierarchy?
 
Nousheed Mohammed
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Using == operator we can compare instances of the same class.
 
Per Radfe
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic