Skip to content

Commit 7441bad

Browse files
committed
Make SerializedFunction.alwaysReturns more reliable.
1 parent f0ff576 commit 7441bad

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/src/main/java/com/diffplug/spotless/SerializedFunction.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ static <T> SerializedFunction<T, T> identity() {
2424
}
2525

2626
static <T, R> SerializedFunction<T, R> alwaysReturns(R value) {
27-
return unused -> value;
27+
return new AlwaysReturns(value);
28+
}
29+
30+
class AlwaysReturns<T, R> implements SerializedFunction<T, R> {
31+
private static final long serialVersionUID = 1L;
32+
private final R value;
33+
34+
AlwaysReturns(R value) {
35+
this.value = value;
36+
}
37+
38+
@Override
39+
public R apply(T t) {
40+
return value;
41+
}
2842
}
2943
}

0 commit comments

Comments
 (0)