polygene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Niclas Hedhman <nic...@hedhman.org>
Subject Re: Type system in Java is bizarre... Help!
Date Wed, 26 Aug 2015 10:26:13 GMT
Well, I don't know if it will help... But, what I finally managed was to
change the visibleXyz() to return

Stream<ModelModule<? extends ModelDescriptor>>

and then get all other parts converging on that. TypeLookUp class is solved.

If we later can tighten the <? extends ModelDescriptor> in each method to
return the specific type, then that would be great, otherwise it seems
quite ok to leave it in that fashion too.

Cheers

On Wed, Aug 26, 2015 at 5:59 PM, Paul Merlin <paul@nosphere.org> wrote:

> Niclas Hedhman a écrit :
> > Gang and especially the Type System experts....
> >
> > I am struggling to get the TypeLookup class converted to Stream API, and
> it
> > is because the Java type system (or at least the one built into IntelliJ)
> > to behave strangely.
>
> IDEs that don't directly rely on javac (Eclipse, IDEA) have history of
> showing errors that javac don't show. Especially when new javac versions
> are released, IDE-specific compilers tends to lag. I don't know what's
> IDEA status WRT this. IIRC there was a setting to tell it to use
> in-process javac.
>
> > For instance; I have the following method in ModuleInstance
> >
> > public Stream<ModelModule<ObjectDescriptor>> visibleObjects(
> > Visibility visibility )
> >
> > And trying to access it from TypeLookup
> >
> > Stream<ModelModule<? extends ModelDescriptor>> moduleObjects =
> > moduleInstance.visibleObjects( module );
> >
> > But that tells me that the moduleObjects are of the wrong type, and
> should
> > be Stream<ModelModule<ObjectDescriptor>>. I can also change the
> > visibleObjects() method to
> >
> > public Stream<ModelModule<? extends Descriptor>> visibleObjects(
> > Visibility visibility )
> >
> > without compile error in TypeLookup NOR in ModuleInstance. What magic
> > happens (or not) in this distinction.
> I tried to reproduce locally and javac behave just has you described. So
> IDEA does a good job here.
>
> Here is what works;
>
> public Stream<ModelModule<ObjectDescriptor>> visibleObjects(Visibility
> visibility)
>
>
> Usage;
>
> Stream<? extends ModelModule<? extends ModelDescriptor>> visibleObjects
> = lookup.visibleObjects();
>
>
>
> So, one need to chain the '? extends T' when implicitely casting on
> 'deep' generics ; eg:
>
> List<List<Integer>> someLists = new ArrayList<>();
> List<List<Number>> numberLists = someLists; // Fails to compile!
> List<? extends List<? extends Number>> deepGenericCast = someLists; // OK
>
>
> HTH
>
> Cheers
>
>


-- 
Niclas Hedhman, Software Developer
http://zest.apache.org - New Energy for Java

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message