scala - Pattern matching Type as a parameter for functions, methods, etc -


i making progress scala's pattern matching (amazing btw) until tried make dynamic function match "instance of" , in future part of object maybe save [type] later. understand how use pattern class matching

case x:int => ....

but why (below) seem work passed it?? further more can't seem work [type] , object? can't print or val = , etc.. thought trying work java.class associated doesn't seem correct. advise appreciated, thank you!

class parent  class child extends parent  object testtypes {    def testrelate[type](o:any) = {       o match {        case o:type => println(" o matching type")        case _  => println(" o fails")      }       // val save = [type]  .. why can't this?   }    def main(args: array[string]): unit = {      val p = new parent     val c = new child     testrelate[int](c)   // why match???     testrelate[parent](c)   //     }  } 

--- update clarify (and thank answers) how can accomplish pattern matching of classtype dynamically during runtime? seems scala has static type matching (that beings breakdown in example above), instanceof( ) choice of dynamic checking?

type parameters erased @ run time, type equivalent object, means anything.

also type parameters types, not values, can't assign variable. @ most, this:

type save = type 

however, erased too, isn't saving anything.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -