Are you planning to release a future version of Java?

yield is one of the best C # features that I skip when programming in Java. Any chance it will be included in Java 7 or 8?

I know that there have been attempts to imitate this function, which I ask specifically is the inclusion of a lesson as a first-class keyword in the official Java assembly.

+6
java yield c # language-features
source share
3 answers

There are no plans that I can see. Definitely not planned for Java 7 or 8.

And if you are talking specifically about adding a new keyword to the language, the probability that this happens is basically 0. Yes, it happened earlier (with a statement, etc.), but there must be a pretty damn convincing reason to add it! I doubt that such a proposal would fall into this category.

However, to be honest, I would not include it in Java in the first place. We already have an iterator interface, and it is great / good enough to use without the need for separate functionality.

If you code in Java, then the Java way is how you need to do something! All this relates to adaptation to various languages ​​and coding to the convention. For one, I don’t want Java to get cluttered by downloading more "just add this!" requests - especially in this regard, everything is fine as it is, and there is very little gain (IMO), adding to such functions.

-2
source share

I would suggest that Java should support closure first, and yield is an extension. Java tends to be a minimalistic language, and there are many ways to do this (although not so elegantly)

In the above example, it would be more appropriate to embed a Power method like this.

 static void Main(String... args) { // Display powers of 2 up to the exponent 8: for(int i = 1; i <= (1 << 8); i *= 2) System.out.println(i); } 

As you can see, this is much shorter, although it may not be as clear how this is done.

BTW: 1 - 2 ^ 0 and degree 2.

EDIT: Java is not a rich language and does not encourage different styles of programming without giving them good support (and looking really ugly as a result). However, this can be done as follows.

 public static Iterable<Integer> power(int base, int exponent) { List<Integer> ints = new ArrayList<Integer>(); for (int i = 1; exponent-- >= 0; i *= base) ints.add(i); return ints; } public static void main(String... args) { for (int i : power(2, 8)) System.out.print(i + " "); } 

Print

 1 2 4 8 16 32 64 128 256 
+1
source share

According to recently released plans for Java 7 and Java 8, the answer is no. There is still time to add it in Java 8, but I doubt anyone is working on this feature. And in Java 9 or later ... who knows.

If you have a part of a project where you can use this feature, you can try alternative JVM languages ​​such as Scala for this part of the project. I believe some of them include similar features.

0
source share

All Articles