HMap uses an evidence implicit to prove that you're allowed to put the key/value pair in the map. You have to encode the constraint you want in an implicit that is available when you're building the HMap or putting values into it or getting values from it.

import shapeless.HMap

class HMapExample {

    class InstanceOfConstraint[K, V]

    implicit def instanceOfClass[T] = new InstanceOfConstraint[Class[T], T]

    val defaultValues = HMap[InstanceOfConstraint](
      classOf[String] -> "Hello",
      classOf[Int] -> 23

Should do what you need.

Related Query

More Query from same tag