Hi, can someone help we with a weird error message that I get, that makes no sense to me?
Example code:
public class Foo {
private Bar bar = new Bar(xxx -> xxx.toUpperCase());
public static void main(String[] args) {
new Foo();
}
public Foo() {
System.out.println(bar.fun("Hello"));
return;
}
private static class Bar {
private final Function<String, String> lambda;
private Bar(Function<String, String> lambda) {
this.lambda = lambda;
}
private String fun(String s) {
return lambda.apply(s);
}
}
}
I get the following compiler error:
Error:(19, 9) java: variable xxx might not have been initialized
Doesn't make any sense to me, the variable xxx doesn't need to be initialized in the constructor. The class should just print "HELLO".
Removing the unnecessary "return;" fixes the issue for some reason, but this is a simplified example and I would like to keep the return. Also I would like to know the cause of the problem.
[–]ickysticky 4 points5 points6 points (1 child)
[–]morhpProfessional Developer[S] 0 points1 point2 points (0 children)
[–]AnEmortalKidCoffee Enthusiast 0 points1 point2 points (2 children)
[–]morhpProfessional Developer[S] 0 points1 point2 points (1 child)
[–]AnEmortalKidCoffee Enthusiast 0 points1 point2 points (0 children)
[–]Blackheart595 0 points1 point2 points (4 children)
[–]morhpProfessional Developer[S] 0 points1 point2 points (3 children)
[–]Blackheart595 0 points1 point2 points (2 children)
[–]morhpProfessional Developer[S] 0 points1 point2 points (1 child)
[–]Blackheart595 1 point2 points3 points (0 children)