Two Laptop Bag
The moose likes Beginning Java and the fly likes generics - duplicate method declaration Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "generics - duplicate method declaration" Watch "generics - duplicate method declaration" New topic
Author

generics - duplicate method declaration

Asha Venkata
Greenhorn

Joined: Jun 17, 2008
Posts: 1
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

Joined: Jul 08, 2003
Posts: 24081
    
  15

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.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: generics - duplicate method declaration
 
Similar Threads
Overloading methods w/ generics causing erasure error
Accessing a valiable outside the class
generics and class literals
Generic method
Generics and interface inheretence