Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
MICHAIL MOUDATSOS
Type parameter bound as Service method return type
1 de Março de 2013 05:22
Resposta

MICHAIL MOUDATSOS

Ranking: Regular Member

Mensagens: 110

Data de entrada: 4 de Outubro de 2011

Mensagens recentes

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 de Março de 2013 06:32
Resposta

David H Nebinger

Community Moderator

Ranking: Liferay Legend

Mensagens: 11464

Data de entrada: 1 de Setembro de 2006

Mensagens recentes

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 de Março de 2013 07:04
Resposta

MICHAIL MOUDATSOS

Ranking: Regular Member

Mensagens: 110

Data de entrada: 4 de Outubro de 2011

Mensagens recentes

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!