Instanceof is a binary operator that tests whether an object is the subtype of a given type. Ex:
Object fonte = e.getSource();
if (fonte instanceof JButton){
...
}
If getSource () returned information from a JButton the result of the expression will be true .
What I do not understand is why the return of the expression is true, since the return of getSource () is an object type, so every object is a JButton subtype If I have:
Object fonte = e.getSource();
if (fonte instanceof JLabel){
...
}
Assuming that getSource () now returns information about a JLabel , how differentiation happens since source is always of type Object ? Instanceof will test the content of source ?