Foren
Type parameter bound as Service method return type
MICHAIL MOUDATSOS, geändert vor 11 Jahren.
Type parameter bound as Service method return type
Regular Member Beiträge: 110 Beitrittsdatum: 04.10.11 Neueste 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
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!
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 evenpublic <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!
David H Nebinger, geändert vor 11 Jahren.
RE: Type parameter bound as Service method return type
Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste 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.
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, geändert vor 11 Jahren.
RE: Type parameter bound as Service method return type
Regular Member Beiträge: 110 Beitrittsdatum: 04.10.11 Neueste BeiträgeDavid 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 ). 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!