Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

generics - duplicate method declaration

 
Asha Venkata
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Can someone please explain why the Java compiler considers the following to be duplicate definition of the method foo():

public void foo (List<String> x) {}
public void foo (List<Integer> x) {}

Thanks
Asha
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

Java generics work by erasure, meaning that they're largely a compile-time abstraction. At runtime, all reference to the type parameter is removed -- which means these two methods are identical.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic