Skip to content

Instantly share code, notes, and snippets.

View pawelpanasewicz's full-sized avatar
💭
Constantly eager to learn and understand more

Paweł Panasewicz pawelpanasewicz

💭
Constantly eager to learn and understand more
  • PANASOFTiX
  • United Kingdom
View GitHub Profile
@pawelpanasewicz
pawelpanasewicz / Spec.scala
Created December 24, 2015 13:17
common spec
package infrastructure
import org.scalatest.prop.PropertyChecks
import org.scalatest._
class Spec
extends FreeSpec
with MustMatchers
with DiagrammedAssertions
with PropertyChecks
@pawelpanasewicz
pawelpanasewicz / gist:f4185e5c1a18b4a5b147
Last active August 29, 2015 14:07
stackable modifications
trait Animal{
println ("creating Animal")
def speak: String
}
trait PrettyAnimal extends Animal{
println ("creating Pretty Animal")
abstract override def speak = s"Pretty(${super.speak})"
}
@pawelpanasewicz
pawelpanasewicz / gist:8625657
Last active August 26, 2019 14:41
scala reflection - how to change (not only) private field
import scala.reflect.runtime.universe._
import scala.reflect.ClassTag
def setField[O: ClassTag, FV](obj: O, fieldName: String, fieldValue: FV)(implicit ev: TypeTag[O]): O = {
import scala.reflect.api.JavaUniverse
val ru: JavaUniverse = scala.reflect.runtime.universe //runtime universe
val runtimeMirror: ru.type#Mirror = ru.runtimeMirror(obj.getClass.getClassLoader)
val instanceMirror: ru.type#InstanceMirror = runtimeMirror.reflect(obj)
val fieldTerm: ru.type#TermName = ru.newTermName(fieldName)
val fieldSymbol: ru.type#TermSymbol = ru.typeOf[O].declaration(fieldTerm).asTerm.accessed.asTerm