Hier ist mein Problem:statische Initialisierungsblocks Rückkehr als nichtig
public class Class5
{
static int ia, ib;
public static Class5 InstanceClass5 = new Class5();
public Class5()
{
this(1, 2);
}
public Class5(int ia)
{
this(ia, 0);
}
public Class5(int ia, int ib)
{
this.ia = ia;
this.ib = ib;
}
// the only one important part of this class code
public static void returnConstructor(int ia, int ib)
{
}
// ends here, the rest isnt important
public static int myVar = initializeClassVariable();
private static int initializeClassVariable()
{
int ia = 3;
return ia;
}
}
public class Main
{
static Scanner dataEntrance = new Scanner(System.in);
public Main()
{
}
public static Main Instancia1Main = new Main();
static int ia, ib;
// here my problem begins: i just did 2 static blocks initializers, but its
// working good.
public static int varType = InitializeClassVariable();
private static int InitializeClassVariable()
{
ia = Class5.ia;
return ia;
}
public static int varType2 = InitializeClassVariable2();
private static int InitializeClassVariable2()
{
ib = Class5.ib;
return ib;
}
public static void main(String[] args)
{
System.out.println(Class3.Instancia2Class3.Class3());
// It shows that the first static block initializer is doing what it was
// created to do: get the same value as "ia" class variable,
// inside Class5 (so, varType2 or InitializeClassVariable2 method is
// working by the same way, for sure)
System.out.println(Main.varType);
// final Main instancia1Main = Instancia1Main; -- it doenst have any
// importance for now
// AND FINALLY, THERES MY PROBLEM: inside Class5, returnConstructor
// method have 2 arguments: int ia, int ib
// To print this method values, i have to use 2 int arguments: why not
// varType and varType2
// or InitializeClassVariable and InitializeClassVariable2 (both options work by the
// same way... in theory)
// It supposed to work then...
System.out.println(Class5.InstanceClass5.returnConstructor(Main.InitializeClassVariable(), Main.varType2));
}
}
Then it happens Ich habe wirklich keine Ahnung, warum returnConstructor die aufgeführten Argumente empfängt (Main.InitializeClassVariable(), Main.varType2) als nichtig. System.out.println (HauptvarTyp); -> Es zeigt, dass varType nicht void ist, und varType2 das gleiche, jemand hat eine Idee, warum es passiert und wie das zu beheben? Ich denke, das ist alles, thx jeder!
Ich habe gerade mit Java begonnen, kann nicht glauben, dass ich diesen Fehler gemacht habe. Danke Pablohan – FARS