![]() ![]() -release 8 specifies that the boot classpath for Java 8 should be used when compiling the sources.For Java 14 it enables us to use text blocks and pattern matching. -enable-preview lets you use the preview features of the used Java compiler.# No need to specify TargetVersion as the -release parameter implies it #TargetVersion: 8, SDKs: ) However, with the () build task for saker.build you can circumvent this restriction: ( SourceDirectories: src, When using javac directly (or via other means), it won't allow you to do this and report an error for mismatching configuration. To use these features while targetting Java 8, you need to set the release, and source version parameters for the Java compiler. Var stream = list.stream() // infers Stream Var list = new ArrayList() // infers ArrayList The compiler will deduce the type of the variable for you: // from Local type inference was introduced in Java 10 and allows you to declare local variables with the var keyword. ![]() Text blocks let you declare string literals that consist of multiple lines without dealing with concatenation and escaping: // from It basically allows you to use switch in more places as well as returning values from them: // from Ĭase MONDAY, FRIDAY, SUNDAY -> (6) Ĭase THURSDAY, SATURDAY -> (8) Switch expressions for Java was standardized in Java 14. (Skip this if you're already familiar with them.) Switch expressions Some of the notable language features that were added since Java 8 are the following: The examples for the post is available on GitHub: java-target-older-releases. Let's change that!Īs an update to the saker.build system, you can now configure the Java compilation in a way that lets you use (some of) the new language features while still being able to run on Java 8. If you're anything like us, you probably haven't even tried them out due to the fact that our code still has to run on Java 8. If you've been following the news about the Java language, you probably know that among others, switch expressions, text blocks, and local type inference has been introduced to the language. Using switch expressions, text blocks, and var on Java 8
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |