This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes generics - duplicate method declaration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "generics - duplicate method declaration" Watch "generics - duplicate method declaration" New topic

generics - duplicate method declaration

Asha Venkata

Joined: Jun 17, 2008
Posts: 1

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) {}

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183


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]
subject: generics - duplicate method declaration
Similar Threads
Generics and interface inheretence
Overloading methods w/ generics causing erasure error
generics and class literals
Generic method
Accessing a valiable outside the class