Groovy web console

subscribe to the feed Subscribe
to this
site
Typecheck test (via #groovywebconsole)
tweet this snippet Tweet
this
script

Typecheck test

Published 1 month ago by Jim L with tags typecheck sanity check
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.transform.TypeChecked;
  
def h = new Hello();
h.run();
 
class Hello {
   
   def run(){
      Set<Integer> integerSet = someMethod([1:"one", 2:"two", 3:"three"])
      println(integerSet)
      Set<String> stringSet = someMethod(["one":1,"two":2,"three":3])
      println(stringSet)
      stringSet = this.<String>someMethod(["one":1,"two":2,"three":3])
      println(stringSet)
   }
   
   private <T> Set<T> someMethod(Map<T, String> someArg) {
        return someArg.keySet()
    }
}