fork(1) download
  1. import java.util.SortedMap;
  2. import java.util.TreeMap;
  3.  
  4. class Ideone
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. SortedMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
  9.  
  10. // Create incorrectly typed entry:
  11. ((SortedMap)map).put("hello", "world");
  12.  
  13. // Map now contains Strings:
  14. System.out.println(map);
  15.  
  16. // This would now cause an exception:
  17. //map.put(3, 4);
  18. }
  19. }
  20.  
Success #stdin #stdout 0.06s 27688KB
stdin
Standard input is empty
stdout
{hello=world}