Mam klasę taką o:
case class CountriesDto(
isoCode: String,
name: String,
languagesIsoCodes: String,
isEnabled: Boolean
)
i tworzę ten obiekt:
Class.forName(CountriesDto.getClass.getName).getDeclaredConstructors()(0).newInstance("aa", "aa", "aa", true)
Error:(23, 120) the result type of an implicit conversion must be more specific than Object
Error:(23, 120) type mismatch;
found : Boolean(true)
required: Object
inna próba:
val obj: Array[Any] = Array("aa", "aa", "aa", true)
Class.forName(CountriesDto.getClass.getName).getDeclaredConstructors()(0).newInstance(obj)
java.lang.IllegalAccessException: Class com.julian.monitor.job.io.dao.postgres.CountriesPostgresDao can not access a member of class com.julian.monitor.job.io.dto.CountriesDto$ with modifiers "private"
W 2 przypadku pewnie nie trafia w ogóle w ten mój konstruktor, bo nie ma konstructora CountriesDto(Any, Any, Any, Any)
a w 1 to nie wiem co on chce.
Używam refleksji, bo chcę zrobić automatyczne inicjowanie dowolnego Dto
mając java.sql.ResultSet
. Każde Dto
będzie miało nazwy zmiennych takie same jak nazwy kolumn ResultSet
.