Is there any way around this?

Is it possible to pass an argument from main to an inner class without wrapping it up in a final String array of length 1?
    public static void main(String[] args) {
        final String[] filename = new String[1];
        if(args.length != 1){
            System.exit(0);
        filename[0] = args[0];
        SwingUtilities.invokeLater(new Runnable(){
            public void run(){
                JFrame jf = new SomeFrame(filename[0]);
                jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                jf.pack();
                jf.setVisible(true);
    }

Hmm, final arguments. That actually makes sense. Wonder why you don't see that more often on examples or when your IDE creates the main for you.
And in response to someone's suggestion about just declaring it final when you need it....
final String filename = args[0];I am actually setting it in different places depending on the number of arguments.
The first example I put was pretty stripped down...
    public static void main(String[] args) {
        final String[] filename = new String[1];
        final int[]    portnumber = new int[1];
        portnumber[0] = 0;
        try{
            if(args.length == 1){
                if(args[0].contains(".svg")){
                    filename[0] = args[0];
                } else {
                    throw new IllegalArgumentException();
            } else if(args.length == 3){
                if(args[0].equals("--listenPort") && args[2].contains(".svg")){
                    filename[0] = args[2];
                    portnumber[0] = Integer.parseInt(args[1]);
                    if(portnumber[0] < 0)
                        throw new IllegalArgumentException();
                } else {
                    throw new IllegalArgumentException();
            } else {
                throw new IllegalArgumentException();
        } catch (IllegalArgumentException ex){
            showUsage();
            System.exit(0);
        SwingUtilities.invokeLater(new Runnable(){
            public void run(){
                JFrame jf = new SVGViewer(filename[0], portnumber[0]);
                jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                jf.pack();
                jf.setVisible(true);
    }

Similar Messages

Maybe you are looking for