Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Generic class cannot subclass java.lang.Throwable?
Generic class cannot subclass java.lang.Throwable? [message #240859] Tue, 20 February 2007 06:53 Go to next message
Eclipse UserFriend
Originally posted by: mauro.molinari.cardinis.com

Hello!
Before reporting a bug against JDT, I would like to ask you what you
think about this strange behaviour of Eclipse against Sun JDK Compiler.

Suppose you have this class:

public class Test<T>
{
public class C extends RuntimeException{}
}

Eclipse gives the following compile-time error: generic class Test<T>.C
may not subclass java.lang.Throwable.
I really cannot understand why...

The error goes away if I declare C as static.

With Sun's JDK compiler, the above code compiles with neither errors nor
warnings (even if C is not declared static)...

Is it a JDT bug? Or a JDK compiler bug?

Cheers,
Mauro.
Re: Generic class cannot subclass java.lang.Throwable? [message #240869 is a reply to message #240859] Tue, 20 February 2007 09:08 Go to previous messageGo to next message
Eclipse UserFriend
Mauro Molinari a écrit :
> Is it a JDT bug? Or a JDK compiler bug?
Looks like a JDT bug.
I opened https://bugs.eclipse.org/bugs/show_bug.cgi?id=174766 to track
it down.
Thanks for the report.
--
Olivier
Re: Generic class cannot subclass java.lang.Throwable? [message #240879 is a reply to message #240869] Tue, 20 February 2007 09:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mauro.molinari.cardinis.com

Olivier Thomann ha scritto:
> Looks like a JDT bug.
> I opened https://bugs.eclipse.org/bugs/show_bug.cgi?id=174766 to track
> it down.
> Thanks for the report.
> --
> Olivier

Thank you Olivier!

Mauro.
Re: Generic class cannot subclass java.lang.Throwable? [message #240883 is a reply to message #240869] Tue, 20 February 2007 09:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------020308040304040607040609
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit

Olivier,

I wonder if it is a bug in JDT or one in the JDK's javac though. It
seems quite intentional that this is not allowed:

public class MyException<T> extends RuntimeException
{
}

So if the following were allowed, it would be possible to use T within
the Exception, and I think that's why the above is not allowed.

public class X<T>
{
public class MyException extends RuntimeException
{
T getT()
{
return null;
}
}
}

This wouldn't be the first time that the JDT does a better job reporting
errors...


Olivier Thomann wrote:
> Mauro Molinari a
Re: Generic class cannot subclass java.lang.Throwable? [message #240888 is a reply to message #240883] Tue, 20 February 2007 09:40 Go to previous message
Eclipse UserFriend
Ed Merks a écrit :
> This wouldn't be the first time that the JDT does a better job reporting
> errors...
I talked too fast :-). javac 1.6 rejects it.

d:\tests_sources>javac X.java
X.java:2: a generic class may not extend java.lang.Throwable
public class C extends Exception {}
^
1 error

--
Olivier
Previous Topic:3.3M5: JRE_LIB is deprecated
Next Topic:How to attach source to a JAR?
Goto Forum:
  


Current Time: Wed Nov 05 16:32:06 EST 2025

Powered by FUDForum. Page generated in 0.04286 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top