Groovy def l = [1, 2, 3] as BlockingQueue

前端 未结 3 1502
眼角桃花
眼角桃花 2021-01-28 01:46

If I write something like def l = [1, 2, 3] as Socket which is obviously nonsense, I get this:

org.codehaus.groovy.runtime.typehandling.GroovyCastE         


        
3条回答
  •  萌比男神i
    2021-01-28 02:17

    It's just Groovy being cute. It's able to see that you're trying to create a collection, but it can't figure out how to construct a BlockingQueue. It's falling back to a proxied ArrayList. If you'd gone with a type declaration on the left side instead of a "def," it would have blown up. Again, it's getting cute because you're using a def. Annoying, isn't it? :)

提交回复
热议问题