0

if we have a look into the bytecode produced by this case class compilation


case class Person(name: String, age: Int)

we get besides others this method:


public scala.collection.Iterator<java.lang.String> productElementNames();

So, the question is, where it comes from and why it can not be called on a Person's instance like, for instance the other one from the same compiled class

public scala.collection.Iterator<java.lang.Object> productIterator();

I use this versions:


$ scala -version                                                                                                                                                                                              
Scala code runner version 2.13.8 -- Copyright 2002-2021, LAMP/EPFL and Lightbend, Inc.

$ scalac -version                                                                                                                                                                                             
Scala compiler version 2.13.8 -- Copyright 2002-2021, LAMP/EPFL and Lightbend, Inc.

idea screenshot

apnmrv
  • 21
  • 3

1 Answers1

1

Solved

thanks to @DmytroMitin and @ElectronWill

Yes, productElementNames() is a method inherited from the Product.

It is definitely callable in Scala 2.13.8, with which the sample is compiled.

The problem was, that the IDE thought it was Scala 2.12.4, where the Product did not yet contain that method.

apnmrv
  • 21
  • 3
  • You can always check whether your code compiles with `sbt clean compile`. Don't rely completely on what your IDE says. – Dmytro Mitin Oct 22 '22 at 14:56