I was working on my game engine, and it has a “Game” class.
public abstract class Game
{
public Game()
{
setup(); //If you call this method here, It will only initialize the variables to their default value
}
protected void setup()
{
}
}
and then I have my game’s class, which extends Game.
public class MyGame extends Game
{
private boolean useShaderPipeline = true;
public MyGame()
{
//if you call setup here, and not from the super constructor, everything works ok
}
protected void setup()
{
System.out.println(useShaderPipeline); //Prints false
useShaderPipeline = true;
System.out.println(useShaderPipeline); //Prints true
}
public static void main(String args[])
{
new MyGame();
}
}
Ok, looks good so far. But wait… why does the println’s return 0 and false respectively? It looks like they are at their default values. However if you initialize them inside of a method, they work fine.
My best guesses are:
- I fell asleep in the java class where they told me about this. //HIGHLY LIKELY.
- There are aliens in my computer.
- This is a bug, or a corrupt JVM.
What are your thoughts/suggestions to resolve this?
P.S. If you hit tab while typing up up a post, it focuses you on the search bar. Sort of annoying when you are formatting code (Just my $0.02)