3

After declaring a static final instance varibale, one ArrayList object is being assigned to it. But when I am adding one extra semi-colon, it is fine with the java compiler. Here is the code.

import java.util.ArrayList;
import java.util.List;

public class FinalExample {

    private static final List<String> foo = new ArrayList();; //double semicolons are fine with compiler

    public static void main(String[] args){
        System.out.println(FinalExample.foo);//Result is - []
    }
kaushik_pm
  • 295
  • 3
  • 10
  • Are you expecting the empty statement to make the preceding assignment fail? – ernest_k Jun 28 '18 at 10:31
  • I searched the [JLS](https://docs.oracle.com/javase/specs/jls/se10/html/index.html) for some insight. But in fact, I can only find a section about the [_empty statement_](https://docs.oracle.com/javase/specs/jls/se10/html/jls-14.html#jls-14.6), nothing about _empty declarations_. But be assured, it will be the same behavior. – Seelenvirtuose Jun 28 '18 at 10:39

1 Answers1

1

A semicolon ends a statement. So when you give multiple semicolons in java the compiler thinks the second semicolon as en empty statement and does not complains for it.

VKR
  • 64
  • 4