Lombok 1.18.0
Works:
Stream.of(DocumentCapability.DOCUMENT_TO_PDF, DocumentCapability.DOCUMENT_TO_TEXT)
.map(
c -> {
CapabilityStatusRecord s = new CapabilityStatusRecord();
s.setCapability(c);
return s;
})
.collect(Collectors.toList());
Doesn't work:
Stream.of(DocumentCapability.DOCUMENT_TO_PDF, DocumentCapability.DOCUMENT_TO_TEXT)
.map(
c -> {
val s = new CapabilityStatusRecord();
s.setCapability(c);
return s;
})
.collect(Collectors.toList());
Thanks!
Hello @dodalovic ,
do you still have this problem with val? What are your steps to reproduce this behavior?
The error text "java: Cannot use 'val' here because initializer expression does not have a representable type: Type cannot be resolved" comes from lombok.jar, not from lombok-plugin.
Similar example: https://github.com/rzwitserloot/lombok/issues/729
I can only reproduce it, if I make a mvn clean first and try to recompile only the class with "val in lamda" after that.
But if I compile with maven or build entire project in IntelliJ, everything is fine.
val-processing needs all other classes to be already compiled, before processing references to it. So it would be correct behavior.
I'm seeing the aformentioned behavior in 1.18.4. (using gradle/intellij (with latest plugin circa 2018-12-01))
-Surprisingly its happening within a 'try' as opposed to a lamda-
Looks like this might be a red herring. The root of the issue was:
val future = CompletableFuture.supplyAsync(() -> CompletableFuture.completedFuture(1));
try {
val result = future.get();
...
explicitly defining the generic type solved the problem:
val future = CompletableFuture.<Integer>supplyAsync(() -> CompletableFuture.completedFuture(1));
I see this when combining val with another example, where there is an generic return type.
public static <T> T or(T object, T ifNull) {
return object != null ? object : ifNull;
}
String x = "b";
val y = x.or("a");
val z = ObjectExtensions.or(x, "a");
Delombok infers Object instead of String:
String x = "b";
final java.lang.Object y = x.or("a");
final java.lang.Object z = ObjectExtensions.or(x, "a");
Most helpful comment
I'm seeing the aformentioned behavior in 1.18.4. (using gradle/intellij (with latest plugin circa 2018-12-01))
-Surprisingly its happening within a 'try' as opposed to a lamda-
Looks like this might be a red herring. The root of the issue was:
explicitly defining the generic type solved the problem:
val future = CompletableFuture.<Integer>supplyAsync(() -> CompletableFuture.completedFuture(1));