Skip to content

Commit c22dc55

Browse files
ctruedengselzer
authored andcommitted
Nil: enable type-safe wrapping of raw types
1 parent 31408e8 commit c22dc55

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

  • src/main/java/org/scijava/ops/types

src/main/java/org/scijava/ops/types/Nil.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ public Nil(final Object callbacks) {
9595
this.callbacks = callbacks(callbacks);
9696
}
9797

98+
/**
99+
* Creates a {@code Nil} wrapping the given raw {@link Class}.
100+
* <p>
101+
* This method is intentionally private; use {@link Nil#of(Class)} to create
102+
* such a {@code Nil} from calling code.
103+
* </p>
104+
*/
105+
private Nil(final Class<T> rawType) {
106+
typeToken = TypeToken.of(rawType);
107+
callbacks = this;
108+
}
109+
98110
/**
99111
* Creates a {@code Nil} wrapping the given generic {@link Type}.
100112
* <p>
@@ -122,6 +134,10 @@ private Nil(final Type type, final Object callbacks) {
122134

123135
// -- Static utility methods --
124136

137+
public static <T> Nil<T> of(final Class<T> rawType) {
138+
return new Nil<T>(rawType) {};
139+
}
140+
125141
/**
126142
* Creates a {@code Nil} of the given generic {@link Type}, with no extra
127143
* method callbacks.

0 commit comments

Comments
 (0)