is this the right mailing list for javax.lang.model.* discussions?

if yes:

instead of adding
    /**
     * Returns the version as int representing the feature release.
     * @see Runtime.Version#feature()
     */
    public int feature() {
        return this.ordinal();
    }
to SourceVersion.

a note could be added to the doc that the ordinal can be used as feature version. Since this statement would apply to the past too, the note could be backported to all maintained JDKs. This comes with the usual downside of not being able to add enums for in-between versions in future.

(doing both would be an option too of course)


To not use the ordinal, client code has to go through some enum init rituals to be able to do version comparisons:

   final static SOURCE_VERSION_RELEASE_18;
   static {
SourceVersion tmp18;
        try {
            tmp18 = SourceVersion.valueOf("RELEASE_18");
        } catch (IllegalArgumentException ex) {
tmp18 = null;
        }
        SOURCE_VERSION_RELEASE_18 = tmp18;
        //... more versions
   }
just to be able to

    if (SOURCE_VERSION_RELEASE_18 != null && version.compareTo(SOURCE_VERSION_RELEASE_18) >= 0) {}

or

    if (Integer.parseInt(version.name().substring(version.name().indexOf('_')+1)) >= 18) {}

which is shorter but not a good solution either.

what the client code actually wants is:

    if (SourceVersion.latest().feature() >= 18) {}


it was a wise decision for java.lang.Runtime.Version to not use enums :)

best regards,
michael



On 09.10.21 20:58, Michael Bien wrote:
Hello,

could javax.lang.model.SourceVersion receive a feature() method returning the version as an int, analog to java.lang.Runtime.Version?

if (SourceVersion.latest().feature() >= 18) {}

is simpler than comparing enums which may or may not exist dependent on the deployed java version and cleaner than ordinal() tricks.

best regards,

michael

Reply via email to