Now this isn’t available unless you compile the latest development version of processing by SamPottinger
Now here is why you might want to use the @FunctionalInterface annotation:-
usefully even before you try to compile/run the sketch you get a warning in the ide, but try to compile/run and you get a nice error message. Functional interfaces can only have one abstract method…
4 Likes
The last time I checked compiled version did not support var.
You could use float instead of var but it would not be surprising!!!
Update 2 Sept 2019
var now supported in latest Sam Potter binary release.
1 Like
Thanks for sharing this.
Anyone can use the Java10 var
as they like, of course, but based on my limited exposure I’m not keen on incorporating use of var into Processing reference / examples for language learners.
My thinking: given that Java is still statically typed, it seems to me like using “var” is an advanced feature for people with a deep understanding of types – the coder still needs to understand that their var is actually an int or float or String and cannot be reassigned, but that is no longer explicit in their sketch. In particular, people switching back and forth between p5.js / Processing may be deeply confused by var in Processing(Java) examples, because it is the “same” keyword but with very different usage rules. The primary point of contact will be people pasting p5.js sketches into Processing PDE (Java mode) and trying to edit them until they work–and that might go okay, but the new errors may be much more confusing than the old ones were that simply rejected the keyword.
I did see one use of var
that made potential sense to me for learners: to shorten very long object declarations, making them more readable and less redundant / intimidating.
// from
ArrayList<PVector> points = new ArrayList<PVector>();
// to
var points = new ArrayList<PVector>();
For advanced users, that answer also mentions var for anonymous types as an alternative to lambdas.
That’s not a good example, b/c var
is for local variables only, and points seems to me it is a “global” field:
The local variable type inference (or Java 10 var keyword) can only be used to declare local variables , e.g. inside methods, on initializer code block, indexes in the enhanced for loop, lambda expressions, and local variables declared in a traditional for loop.
Personally I think there is often a lot too much ceremony with java code, effectively you declare types twice when you don’t need to inside a method. Processing has done away with explicitly calling methods public for the sake of brevity.