Skip to content

Commit acf48c1

Browse files
committed
WrapperService: fix create method return type
It will -- and should -- always return an instance of PT specifically. That is the point of the generic typing on plugin type: to define and guarantee use of that specific type. Not just "WrapperPlugin<D>". This change will eliminate a few hacky casts downstream, too.
1 parent 4221e12 commit acf48c1

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

src/main/java/org/scijava/plugin/AbstractWrapperService.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,13 @@ public abstract class AbstractWrapperService<DT, PT extends WrapperPlugin<DT>>
5050
// -- WrapperService methods --
5151

5252
@Override
53-
public <D extends DT> WrapperPlugin<D> create(final D data) {
53+
public <D extends DT> PT create(final D data) {
5454
final PT instance = wrap(data);
5555
if (instance == null) {
5656
throw new IllegalArgumentException("No compatible " +
5757
getPluginType().getSimpleName() + " for data object: " + data);
5858
}
59-
@SuppressWarnings("unchecked")
60-
final WrapperPlugin<D> typedInstance = (WrapperPlugin<D>) instance;
61-
typedInstance.set(data);
62-
return typedInstance;
59+
return instance;
6360
}
6461

6562
// -- Service methods --

src/main/java/org/scijava/plugin/WrapperService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ public interface WrapperService<DT, PT extends WrapperPlugin<DT>> extends
6262
* @throws IllegalArgumentException if the data is not compatible with any
6363
* available plugin.
6464
*/
65-
<D extends DT> WrapperPlugin<D> create(D data);
65+
<D extends DT> PT create(D data);
6666

6767
}

0 commit comments

Comments
 (0)