Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 22429 Details for
Bug 98538
[1.5][compiler] Inference broken for subtypes of subtypes of F-bounded types
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Full source code that exhibits compilation errors
TestGenerics.java (text/plain), 2.91 KB, created by
Matt McHenry
on 2005-06-06 11:59:04 EDT
(
hide
)
Description:
Full source code that exhibits compilation errors
Filename:
MIME Type:
Creator:
Matt McHenry
Created:
2005-06-06 11:59:04 EDT
Size:
2.91 KB
patch
obsolete
>//********************************************************************* >// >// Copyright (C) 2005 >// Carnegie Learning Inc. >// >// All Rights Reserved. >// >//This program is the subject of trade secrets and intellectual >//property rights owned by Carnegie Learning. >// >//This legend must continue to appear in the source code despite >//modifications or enhancements by any party. >// >//********************************************************************* > >/* > $Id$ > $Name$ >*/ > >package cl.sdk.common.testcode; > >import java.util.Collections; >import java.util.List; > >public class TestGenerics { > > /**Subclasses are parameterized by their own type*/ > private static abstract class SelfType<T extends SelfType<T>>{ > public abstract T getThis(); > } > > /**Supertype inherits directly from the parameterized SelfType*/ > private static class SuperType extends SelfType<SuperType>{ > @Override > public SuperType getThis(){ > return this; > } > } > > /**Subtype inherits indirectly from the parameterized SelfType*/ > private static class SubType extends SuperType{} > > /**Creates a list containing a single SelfType*/ > public static <T extends SelfType<T>> List<T> makeSingletonList(T t){ > return Collections.singletonList(t); > } > > /** > * Creates a list containing a single SelfType, allowing the list's > * element-type to be a supertype of the type of its single element > */ > public static <T extends SelfType<T>,S extends T> List<T> makeSingletonList2(S s){ > return Collections.singletonList((T)s); > } > > public static void main(String[] args){ > /*making lists of super types works fine ...*/ > makeSingletonList(new SuperType()); > List<SuperType> lsup = makeSingletonList(new SuperType()); > > /*but we can't make a list of sub types; seems weird ...*/ > List<SubType> lsub = makeSingletonList(new SubType()); //ERROR > /*can't even call it w/o assigning the return value:*/ > makeSingletonList(new SubType()); //ERROR > > > /*so instead, we should be able to make lists of super type containing sub type elements*/ > makeSingletonList2(new SubType()); //ERROR > /*even if we assign the return value:*/ > lsup = makeSingletonList2(new SubType()); // ERROR (eclipse is okay with this though) > /*this still doesn't work either:*/ > lsub = makeSingletonList2(new SubType()); // ERROR > > /*we can make lists of super type this way though*/ > makeSingletonList2(new SuperType()); // (eclipse doesn't like this though) > /*also ok if we assign the return value*/ > lsup = makeSingletonList2(new SuperType()); > } >} > >interface FooInterface{} > >enum FooEnum implements FooInterface{FOO} > >class FooParam<P extends Enum<P> & FooInterface>{} > >class FooTest{ > public static void main(String[] args){ > FooParam unparam = null; > method(unparam); > } > > public static <P extends Enum<P> & FooInterface> void method(FooParam<P> fooparam){ > > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 98538
: 22429 |
23536
|
23598