Scala 2.10 TypeTag usage

前端 未结 4 1841
温柔的废话
温柔的废话 2021-02-04 13:27

I\'m digging new scala reflection api and can\'t figure out why the following snippet doesn\'t work as expected. Given hierarchy (tried to simplify as much as I can):

         


        
4条回答
  •  孤街浪徒
    2021-02-04 14:16

    Thanks everyone to feedback. Think, I've found the reason why ClassTag should be used in pattern matching.

    I've managed to find [SI-5143] Pattern matching on abstract types doesn't work, and it's associated commit explains that there should be an instance of ClassTag to make pattern checkable.

    So, yes, I used TypeTag wrong; in case of pattern matching I should use ClassTag.

提交回复
热议问题