scala type inference doesn't figure out the type information -


i have following 2 test cases:

  @test   def testtypeinference1(): unit = {     def echo[a, b>: a](value: a): b = value     println(echo("hello"))   }    @test   def testtypeinference2(): unit = {         def headelem[a, l <: list[a]](list: l): = list.head         val h = headelem(list(1,2,3))         println(h)   } 

test case 1 passed test , print "hello",

but when run test case 2, error occurs, complaining that

error:(2013, 17) inferred type arguments [nothing,list[int]] not conform method headelem's type parameter bounds [a,l <: list[a]]         val h = headelem(list(1,2,3))             ^ 

i ask why test case 1 works while test case 2 fails, looking similar me

thanks.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -