Sunday, 13 January 2019

No primitive types in Groovy


Everything is an object in Groovy. Even primitive types are converted to wrapper types in Groovy.

HelloWorld.groovy
byte a = 10
short b = 20
int c = 30
long d = 40l

float e = 20.05f
double f = 20.05

char g = 'c'
boolean h = true

println "a : ${a}, class : ${a.class}"
println "b : ${b}, class : ${b.class}"
println "c : ${c}, class : ${c.class}"
println "d : ${d}, class : ${d.class}"
println "e : ${e}, class : ${e.class}"
println "f : ${f}, class : ${f.class}"
println "g : ${g}, class : ${g.class}"
println "h : ${h}, class : ${h.class}"

Output
a : 10, class : class java.lang.Byte
b : 20, class : class java.lang.Short
c : 30, class : class java.lang.Integer
d : 40, class : class java.lang.Long
e : 20.05, class : class java.lang.Float
f : 20.05, class : class java.lang.Double
g : c, class : class java.lang.Character
h : true, class : class java.lang.Boolean



Previous                                                 Next                                                 Home

No comments:

Post a Comment