apnmrv
apnmrv

Reputation: 21

Scala case class method: `public scala.collection.Iterator<java.lang.String> productElementNames()`

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

Upvotes: 0

Views: 218

Answers (1)

apnmrv
apnmrv

Reputation: 21

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.

Upvotes: 1

Related Questions