Skip to main content
added 63 characters in body
Source Link
jayunit100
  • 17.7k
  • 23
  • 99
  • 175
  1. This is entirely appropriateMake the method static, butand you will be fine -- static code must be in order must be compiled in order. Put the loadStrings function before the static code block.

Please note : However - you might be better off simply creating a single, static , "init" method, which is called in your static code block . This will be nameable and unit-testable, unlike your current implementation.

  1. By the way : your float syntax is off need to be casted properly.

    By the way : your float syntax is off, and must to be casted properly.

    int i = (int) 1.4f;

  2. To initialize the static variables you can do the following :

  • Declare a static init() method, which reads the file and initializes the static variables.
  • Create a separate FileReader object in a separate class, or a static inner class, which can be invoked to read in variables , and invoke it FROM your static code block.
  • (bad idea) Put the file reading logic inside of your big static code block . this will be very ugly however.
  1. This is entirely appropriate, but static code must be in order must be compiled in order. Put the loadStrings function before the static code block.

However - you might be better off simply creating a single, static , "init" method, which is called in your static code block . This will be nameable and unit-testable, unlike your current implementation.

  1. By the way : your float syntax is off need to be casted properly.
  1. Make the method static, and you will be fine -- static code must be in order must be compiled in order. Put the loadStrings function before the static code block.

Please note : However - you might be better off simply creating a single, static , "init" method, which is called in your static code block . This will be nameable and unit-testable, unlike your current implementation.

  1. By the way : your float syntax is off, and must to be casted properly.

    int i = (int) 1.4f;

  2. To initialize the static variables you can do the following :

  • Declare a static init() method, which reads the file and initializes the static variables.
  • Create a separate FileReader object in a separate class, or a static inner class, which can be invoked to read in variables , and invoke it FROM your static code block.
  • (bad idea) Put the file reading logic inside of your big static code block . this will be very ugly however.
Source Link
jayunit100
  • 17.7k
  • 23
  • 99
  • 175

  1. This is entirely appropriate, but static code must be in order must be compiled in order. Put the loadStrings function before the static code block.

However - you might be better off simply creating a single, static , "init" method, which is called in your static code block . This will be nameable and unit-testable, unlike your current implementation.

  1. By the way : your float syntax is off need to be casted properly.