joewang704 joewang704 - 1 year ago 37
Java Question

Accessing variables from a parent class when using an instance of the child does not seem to be working

I'm trying to port a program in Java over to Scala, however, I'm running into an error.

I have a line that accesses


In Java, this works fine.

However, in Scala this gives the error

value BOOTSTRAP_SERVERS_CONFIG is not a member of org.apache.kafka.connect.runtime.distributed.DistributedConfig

Looking into the
is actually not defined in the class, but defined in
extends. I've checked and the variable is public.
public static final String BOOTSTRAP_SERVERS_CONFIG
is the exact definition.

Answer Source

Java "fakes" inheritance of static members (when you write DistributedConfig.BOOTSTRAP_SERVERS_CONFIG, the Java compiler turns it into WorkerConfig.BOOTSTRAP_SERVERS_CONFIG), Scala doesn't because it wouldn't fit with Scala's approach to statics (using companion objects). So in Scala you can only use WorkerConfig.BOOTSTRAP_SERVERS_CONFIG.