Anonymous class in scala 2.13.10

The following works fine in Scala 2.11.8, do you know any workaround for 2.13.10?
$ ./scala
Welcome to Scala 2.13.10 (Java HotSpot™ 64-Bit Server VM, Java 17.0.6).
Type in expressions for evaluation. Or try :help.

scala> val tt = Class.forName(“scala.reflect.ClassTag$$anon$1”)
java.lang.ClassNotFoundException: scala.reflect.ClassTag$$anon$1
at scala.reflect.internal.util.AbstractFileClassLoader.findClass(AbstractFileClassLoader.scala:75)
at java.base/java.lang.ClassLoader.loadClass(
at java.base/java.lang.ClassLoader.loadClass(
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(
… 32 elided

I’m not sure what’s your use case but it seems that you were refering to ClassTag.GenericClassTag. It’s still present in Scala 2.12 as annonymous class, but in Scala 2.13 it’s encoded as scala.reflect.ClassTag$GenericClassTag

Thanks! it works for me. I use it to initialize some spark stuff (we have upgraded Spark and scala):

I have a similar problem with the following.

In Scala 2.11.8 the following works fine:

How can I determine what the what the equivalent is in Scala 2.13.10?

/* The class */

class KafkaSink(topic: String, createProducer: () => KafkaProducer[String, Array[Byte]]) extends Sink {

lazy val producer = createProducer()
lazy val logger = Logger.getLogger(getClass)

override def send(value: Array[Byte], callback: OutputCallback): Future[_] = {
producer.send(new ProducerRecord(topic, null, null, value), new Callback(){
override def onCompletion(recordMetadata: RecordMetadata, e: Exception): Unit = {
callback.onCompletion(recordMetadata, e)

override def handleExceptions(callback: OutputCallback): Unit = {

object KafkaSink {
def apply(topic: String, config: java.util.HashMap[String, Object]): KafkaSink = {
val f = () => {
val producer = KafkaSinkSingleton.getInstance(topic,config)

  sys.addShutdownHook {

new KafkaSink(topic, f)


Probably you refer to val f = () => {...} in KafkaSink.apply. $anonfun" is an anonymous function. As far I know since 2.12 their encoding has change. Before each anonymous function was encoded as new anonymous class (that’s what we still do in Scala Native). Since 2.12 on the JVM they probably use standard Java 8 lambdas support, though there would be no $anonfun$ class anymore.

Anyway refering to anonymous stuff via reflection is ultra-unsafe. In theory that’s the implementation detail and could change at any moment.If possible, it would be better to refactor the code the remove unsafe, reflection based access.

Thank you for your help.

The Scala 2 repl had a :javap -fun command to show bytecode of anon funs.

It was updated a few times for the evolving encodings but dropped eventually as a maintenance headache.

Although it’s an implementation detail, I think first-class functions includes supporting reflective access for tooling purposes.