Java: design problem with private-final-int-value and empty constructor

Posted by HH on Stack Overflow See other posts from Stack Overflow or by HH
Published on 2010-04-12T02:57:54Z Indexed on 2010/04/12 5:23 UTC
Read the original article Hit count: 228

$ javac InitInt.java 
InitInt.java:7: variable right might not have been initialized
    InitInt(){}
              ^
1 error
$ cat InitInt.java 
import java.util.*;
import java.io.*;

public class InitInt {
    private final int right;

    //DUE to new Klowledge: Design Problem
    //I think having an empty constructor like this
    // is an design problem, shall I remove it? What do you think?
    // When to use an empty constructor?
    InitInt(){}
    public static void main(String[] args) {
        InitInt test = new InitInt();   
        System.out.println(test.getRight());
    }
    public int getRight(){return right;}
}

Initialization problem with Constructor

  InitInt{
           // Still the error, "may not be initialized"
           // How to initialise it?

            if(snippetBuilder.length()>(charwisePos+25)){
                    right=charwisePos+25;
            }else{
                    right=snippetBuilder.length()-1;
            }
   }

© Stack Overflow or respective owner

Related posts about java

Related posts about initialization