Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
MICHAIL MOUDATSOS
Type parameter bound as Service method return type
1. März 2013 05:22
Antwort

MICHAIL MOUDATSOS

Rang: Regular Member

Nachrichten: 110

Eintrittsdatum: 4. Oktober 2011

Neue Beiträge

Hello all.

Assuming I have defined an entity in service.xml, let's say 'MyEntity'

It seems that in MyEntityLocalServiceImpl I can define a method with the following contract

1public List<?> getMyEntities(Class<?> clazz, int myEntityId)
or even
1public List<? extends MyEntity> getMyEntities(Class<? extends MyEntity> clazz, int myEntityId)
but I can't define
1public <T extends ChargingScheme> List<T> getMyEntities(Class<T> clazz, int myEntityId)
and of course not even
1public <T extends ChargingScheme> T getMyEntity(Class<T> clazz, int myEntityId)

From what i know, you can only return Collections, Objects that relate to primitive data types and Entities created by service-builder. The wildcard bound <?> is allowed in a Collection or Class declaration but not the type parameter bound <T>. Can I have, even a short, explanation for this? Or a reference to one.

Thank you all in advance!
David H Nebinger
RE: Type parameter bound as Service method return type
1. März 2013 06:32
Antwort

David H Nebinger

Community Moderator

Rang: Liferay Legend

Nachrichten: 9428

Eintrittsdatum: 1. September 2006

Neue Beiträge

Because the initial SB stuff was done before these things got into Java. SB has undergone some minor changes/enhancements since it's initial launch, and there has been little if any effort put towards integrating these 'new' language features.

Note that SB's principle concept has always been to keep things simple. It does not support entity inheritance, limited support for one to many & many to many relationships, etc. It only works on primitives (and their object counterparts), collections, and entities. It has no shared visibility on any other class/interface (unless loaded from the global class loader), so ChargingScheme may not be visible in all necessary contexts.
MICHAIL MOUDATSOS
RE: Type parameter bound as Service method return type
1. März 2013 07:04
Antwort

MICHAIL MOUDATSOS

Rang: Regular Member

Nachrichten: 110

Eintrittsdatum: 4. Oktober 2011

Neue Beiträge

David H Nebinger:
It has no shared visibility on any other class/interface (unless loaded from the global class loader), so ChargingScheme may not be visible in all necessary contexts.
Woops! my bad there, I should have written MyEntity instead! (guess I didn't manage to anonymize my entity after all emoticon ). So it is what you said about the whole advancement of java language, etc.
Additionally in order to correct something I said:
1List<? extends MyEntity> ..../*and*/...Class<? extends MyEntity>...
does not produce any error while the ant build-service task runs, but in generated code it is converted to
1List<?> ..../*and*/...Class<?>...
,which in turn produces compilation errors. The reason might again lie in your answer so only bare wildcard is supported. The wildcard bound as well as the type parameter bound is not supported.

Thanks a lot!