Constant methods in Java

Alberto Otero Rodríguez albest512 at hotmail.com
Wed Feb 2 19:22:21 UTC 2022


I have a suggestion. I think it would be interesting creating constant methods in Java.

I mean methods declared like this:

public const String myMethod() {
  String a = "a";
  a = a + "b";
  return a;
}

So that the response of the method is forced to be assigned to a final variable.

This would be ok:
final String b = myMethod();

But this would throw a compilation error:
String c = myMethod();

What do you think? It's just an idea.


More information about the amber-dev mailing list