Is it possible to have type parameters (generics) on classes which are not collections in scala? -


as questions suggests. ever make sense think generics on non-collections? have been trying think through. collection 'wrapper' of other objects, there has 'wrapper' direct generic at?

thanks

yep. minimal example, here class wraps of type t, t generic:

scala> class wrapper[t](val x: t) defined class wrapper 

if give int, it's wrapper[int]:

scala> new wrapper(5) res0: wrapper[int] = wrapper@578ef2b6 

if give string, it's wrapper[string]:

scala> new wrapper("this") res1: wrapper[string] = wrapper@3b16bf07 

this directly analogous collection of items of type t:

scala> vector(1,2,3) res2: scala.collection.immutable.vector[int] = vector(1, 2, 3) 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -