How could I convert the following into scala.
public class JedisDB {
private static final JedisPool jedisPool = new JedisPool(getJedisPoolConfig());
public static JedisPoolConfig getJedisPool() {
// ..
}
public int getTest123() {
jedisPool.getResource();
// code goes here
}
}
I have seen answers do create a class and a companion object, but can someone explain to me exactly how and why I should do this?
Should I create what I want to expose as a static variable in the companion object, and the loading of the configuration file that is used to initialize the jedisPool in the class?
Do I have the option of making jedisPool public or private in the companion object?
Also (not to effect the answer to my question but as a added benefit), I read somewhere but didn't fully understand that this makes pattern makes testing difficult, are there workarounds then?