I have code that returns a value as Any. I have a way to get the actual type of this value. This is part of a very reflection-oriented solution.
// Reflecting on a class I have info about its constructor fields:
val fieldMembers: fieldMembersByName: ListMap[String,ClassFieldMember] = ...
// ClassField member has a method valueIn(inst:T): Any, where T is the type
// of the parent class
val nameField = fieldMembers("name").valueIn(personObject)
// This obtains the value of some instance's (personObject's) name field,
// but to Scala the type of nameField is Any. I need to cast it, but to what?
val realType: Type = ... // a bunch of ugly reflection that returns the acutal
// type of the name field, i.e. String here
What I'm looking for is the equivalent of the (syntactically invalid):
val purifiedValue = nameField.asInstanceOf[realType]