Sunday, April 08, 2007

The canonical order of Java modifier names

Introduction

The canonical order of Java modifier names is:

Modifiers =
'public' | 'protected' | 'private' | 'abstract' | 'static' | 'final' | 'transient' | 'volatile' | 'synchronized' | 'native' | 'strictfp' | 'interface' ;
(Modifier (Java 2 Platform SE 5.0))

Program

import java.lang.reflect.*;

public class Main {
    final static strictfp public class MyClass {
    }
    
    public static void main(String[] args) {
        MyClass mc = new MyClass();
        Class c = mc.getClass();
        int m = c.getModifiers();

        // Print the modifier names in canonical order
        System.out.println(Modifier.toString(m));
    }    
}

Output

public static final strictfp

No comments: