aspose file tools
The moose likes Java in General and the fly likes Generics allows extending String class Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Generics allows extending String class" Watch "Generics allows extending String class" New topic
Author

Generics allows extending String class

Akshay Sahu
Greenhorn

Joined: Sep 04, 2009
Posts: 26

Hi,

If I write
Class TestGeneric<E extends String> {}

The compiler allows me to compile this. This shouldn't be allowed as final classes can neither be extended nor can be implemented.

I just want to know why is the compiler allowing that syntax to be valid.


Thanks and Regards,
Akshay Sahu


Akshay Sahu
OCBCD (EJB 3), OCJP (Java SE 6), MCTS (MS SQL Server 2005)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

I don't agree that it shouldn't be allowed. Sure, the only value you can use for E is String itself, but writing a language specification which disallows that is really a waste of time. It just makes things more complicated, which means harder to test and more likely to have bugs.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generics allows extending String class
 
Similar Threads
Primitive assignment
Interface question
Hibernate query question
if-problem
About Runnable and Serializable