Type inference in Sakai code

12 views
Skip to first unread message

Adrian Fish

unread,
Oct 15, 2025, 12:10:08 PMOct 15
to sakai-dev
Hi all,

What are peoples opinions on using type inference in our codebase?
Since Java 10 (Sakai 22+) we've been able to use the var keyword to
declare a variable and assign it a value in one stroke, so:

var userName = new String("Bob");

This, I think, is less cluttered than using the old school:

String userName = new String("Bob");

We know it's a string already. However ...

var userName = api.getUserName();

... doesn't immediately tell you the type. You'd have to look at getUserName().

At the moment, we have our coderabbit rules setup to complain heavily
at the use of type inference.

What do you all think? Should we ban using type inference in our code?

Cheers,
Adrian.

Sebastian Riemer

unread,
Oct 21, 2025, 8:32:03 AMOct 21
to Sakai Development, Adrian Fish
Hi Adrian,

I don’t care much for type inference — I’d rather be explicit about my types. So yes, ban it.

Best regards,
Sebastian

Adrian Fish

unread,
Oct 21, 2025, 8:41:15 AMOct 21
to Sebastian Riemer, Sakai Development
We're not really talking about full blown type inference here though,
not really. We still have full typing but we only have to declare the
type once, on the right hand side or as a method return type. I agree
that using "inference" where the type is declared on the method
declaration can be confusing, but I think that being able to just
type:

var userName = new String("Bob");

and look at that variable 20 lines down, is just as good as

String userName = new String("Bob");

You still see "userName" 20 lines down and would have to work out the
type somehow, via your IDE or just grepping the code. The type
inference discussion reminds me of the literal arguments from the
past. String literals instead of always having to type new String.
> --
> You received this message because you are subscribed to the Google Groups "Sakai Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sakai-dev+...@apereo.org.
> To view this discussion visit https://groups.google.com/a/apereo.org/d/msgid/sakai-dev/9f0d8ef7-1c92-44cf-bd07-e84a9b120775n%40apereo.org.
Reply all
Reply to author
Forward
0 new messages