I have the following Java-class:
public class Permutation {
...
private Permutation(int[] cycle){...} //1
private Permutation(int[] inp, int[] outp){...} //2
public Permutation(int[] array, boolean isCycle){ //3
if(isCycle){
//creation new Permutation through "1"
}
else{
//splitting on input and output arrays and
//creation new Permutation through "2"
}
}
...
}
But I when I tried to realize constructor "3", I cought compile error. I know, that I can realize this logic using static method like this:
public static Permutation createPermutation(int[] array, boolean isCycle){
if(isCycle){
return new Permutation(array);
}
//else branch...
}
Also I know, that call to this()
or super()
must be the first statement in the constructor.
But is it possible to realize exactly constructor with architecture "3" (not static creator or something else) in my class? And if it is possible, how can I do that?
UPD: It is not duplicate to How do I call one constructor from another in Java? because in my problem I should realize some logic before calling this()
method and this is the main part of my problems.