Reputation: 21
I'm learning data structures and encountered the code below. I'm really curious about the meaning of parentheses around new Object();
.
public class HashTable <K,V> implements Iterable<K> {
private final K TOMBSTONE=(K) (new Object());
}
I assume the parentheses around K are for down casting that makes the new Object();
be of data type K
.
What are the parentheses around new Object();
for?
Could you please tell me in plain English?
Upvotes: 2
Views: 95
Reputation: 361635
The parentheses aren't functionally required. They're just there for readability. It would compile without them:
public class HashTable <K,V> implements Iterable<K> {
private final K TOMBSTONE=(K) new Object();
}
Upvotes: 4