eatmore's blog

By eatmore, history, 4 years ago, In English

Java 15 was released a few days ago. Here are some changes that may be useful for competitive programming.

  • Pattern matching for instanceof, first introduced in Java 14, is still a preview.
  • Text blocks, first introduced in Java 13, are now final:
String input = """
	3 3
	1 2
	1 3
	2 3""";
  • Records, first introduced in Java 14, are now final:
record Fraction(int num, int den) {
	Fraction {
		if (den == 0) {
			throw new IllegalArgumentException("zero denominator");
		}
		if (den < 0) {
			num = -num;
			den = -den;
		}
	}

	Fraction add(Fraction o) {
		return new Fraction(num * o.den + den * o.num, den * o.den);
	}

	// ...
}
  • Useful new methods: CharSequence.isEmpty() (also inherited by String), String.stripIndent() (useful for text blocks), String.formatted(), Math.absExact().

Previous posts: Java 8, 9, 10, 11, 12, 13 and 14.

  • Vote: I like it
  • +83
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it -32 Vote: I do not like it

Who uses Java pft

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +59 Vote: I do not like it

    3 billion devices run Java !!

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it -37 Vote: I do not like it

      Quantity != Quality

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it +16 Vote: I do not like it

        And what really makes you think that Java is not a quality language ?

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it +8 Vote: I do not like it

        You asked who uses Java, and saying 3 billion devices run Java seems like a valid reply.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +15 Vote: I do not like it

    Not sure why you're getting downvoted. It is probably a joke.

    But even taken seriously, it's not such a terrible comment. JVM is awesome and if you want to use it, Kotlin is a great alternative to Java. It's like Java 35 with nicer syntax.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

A new feature is added in the form of sealed classes. Here no interface or class can inherit the parent sealed class. Only those class/interface can use the class features which are permitted by the sealed parent class.

Previously, inheritance was revoked by final class. Now, sealed class provide partial revokation with allowing only few structures to inherit them.

»
4 years ago, # |
  Vote: I like it +78 Vote: I do not like it

the feeling from looking away from java 8 for 2 minutes and coming back to find oracle has made java 15 must be what parents feel when their kid goes to university

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    But it seems the only new thing since Java 8 that I actually use is the var keyword :/

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    I thought that Java 7 is the most recent one :|