How do you declare and use a Set data structure in groovysh?

前端 未结 2 619
感动是毒
感动是毒 2021-01-11 18:41

I\'ve tried:

groovy:000> Set s = [\"a\", \"b\", \"c\", \"c\"]
===> [a, b, c]
groovy:000> s
Unknown property: s

I wa

2条回答
  •  粉色の甜心
    2021-01-11 19:09

    Groovy >= 2.4.0
    Setting interpreterMode to true in groovy shell by

    :set interpreterMode true
    

    should fix this issue

    Groovy < 2.4.0
    Adding a type to the variable makes it a local variable which is not available to shell's environment.

    use as below in groovysh

    groovy:000> s = ['a', 'b', 'c', 'c'] as Set
    ===> [a, b, c]
    groovy:000> s
    ===> [a, b, c]
    groovy:000> s.class
    ===> class java.util.LinkedHashSet
    groovy:000>
    

提交回复
热议问题