using labels in java without “loops”

前端 未结 5 564
遇见更好的自我
遇见更好的自我 2020-11-29 12:08

I always thought that the labels must be used only with loops but it seems not. Giving such code:

public class LabelTest {
    public static void main(String         


        
5条回答
  •  感情败类
    2020-11-29 12:56

    It does not compile. Good question! I have just played a little bit with your code snippet. It seems that compiler expects method call or operator after label. It does not allow assignment at this point.

    I think that the fact that label is not forbidden before operators other than for, while and do is probably a bug (?!) of java compiler of specification. Anyway it is not so critical. It does not bother me (personally).

提交回复
热议问题