History | Log In     View a printable version of the current page. Get help!  
Issue Details [XML]

Key: ALI-12
Type: Bug Bug
Status: Resolved Resolved
Resolution: Won't Fix
Priority: Minor Minor
Assignee: James Leigh
Reporter: Erik Godding Boye
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
AilBaba

Object repository compiler generates concepts with non-symmetric accessors for collection properties

Created: 26/Aug/11 10:51 AM   Updated: 26/Aug/11 03:07 PM
Component/s: object-repository
Affects Version/s: 2.0-beta11
Fix Version/s: None


 Description   
The object repository compiler generates getter/setter with different generics for a collection property. The setter is generated with a generics wildcard, but the getter is not. I think the correct behavior should be to use a generics wildcard in both accessors.

An example:
public interface NameType {
   Set<Name> getNameType_Names();
   void setNameType_Names(Set<? extends Name> NameType_Names);
}

I think this should be:
public interface NameType {
   Set<? extends Name> getNameType_Names();
   void setNameType_Names(Set<? extends Name> NameType_Names);
}

 All   Comments   Change History      Sort Order:
Comment by James Leigh [26/Aug/11 03:07 PM]
The getter return type does not use a bounded parameter to allow the returned set to be modified. Unfortunately in Java, you cannot use the add method of a collection with a bounded parameter. By returning a set with an explicit parameter the caller can add new items without casting the results. This code: obj.getNameType_Names().add(aName), would only be possible if the getter returned a set with an explicit parameter.

In the setter, a bounded parameter (not explicit parameter) is declared to allow sets of subclass instances to be passed to the setter. If an explicit parameter was used in the setter Java would not allow a set to be passed if it was declared with a subclass parameter.