掲示板

Type parameter bound as Service method return type

11年前 に MICHAIL MOUDATSOS によって更新されました。

Type parameter bound as Service method return type

Regular Member 投稿: 110 参加年月日: 11/10/04 最新の投稿
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

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

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!
thumbnail
11年前 に David H Nebinger によって更新されました。

RE: Type parameter bound as Service method return type

Liferay Legend 投稿: 14914 参加年月日: 06/09/02 最新の投稿
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.
11年前 に MICHAIL MOUDATSOS によって更新されました。

RE: Type parameter bound as Service method return type

Regular Member 投稿: 110 参加年月日: 11/10/04 最新の投稿
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:
List<!--? 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
List<!--?--> ..../*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!