[MDSAL-394] Generated DataObject interfaces should override DataObject.getImplementedClass() Created: 15/Nov/18  Updated: 25/Nov/18  Resolved: 25/Nov/18

Status: Resolved
Project: mdsal
Component/s: Binding codegen
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Medium
Reporter: Robert Varga Assignee: Robert Varga
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates MDSAL-396 Add DataObject.implementedInterface() Resolved

 Description   

We currently purely inherit this class, which is suboptimal when dealing with generics, most notably this case does not work:

interface Foo extends DataObject;

public <T extends Foo> void doSomething(T foo) {
    Class<? extends T> fooSubclass = foo.getImplementedInterface();
}

While all implementations are already returning the right answer (and if they don't Binding just breaks down), it is not expressed in the interface contract.

This this by generating a default interface method:

interface Foo extends DataObject {
    @Override
    default Class<? extends Foo> getImplementedInterface() {
        return Foo.class;
    }
}

This already exists in Builder's implementation generator, albeit in the form:

@Override
public Class<Foo> getImplementedInterface() {
    return Foo.class;
}


 Comments   
Comment by Robert Varga [ 25/Nov/18 ]

Exposing getImplementedInterface() in binding-model-api is dangerous, hence we'll implement this in MDSAL-396 only.

Generated at Wed Feb 07 20:09:42 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.