How to set up type boundaries of AnyRef to make it only case class

225 Views Asked by At

suppose that i have some case classes

case class Foo(i: Int)
case class Bar(s: String)

i want to define some function that take A : AnyRef as parameter. But! I want to setup it boundaries with:

  1. A is AnyRef but not an Object
  2. A is AnyRef but case class only

something like that

def caseClassProcessor[A](A: AnyRef <: Some bounds) = ???

def notObjectProcessor[A](A: AnyRef ! Object) = ???

is it possible any way?

1

There are 1 best solutions below

0
On

Maybe this example is what you need:

case class Foo(int: Int)
case class Bar(string: String)

def foo[A](arg: A) = arg match {
  case Foo(int)    => ...
  case Bar(string) => ...
  case _           => ...
}