当前位置: 首页 > 工具软件 > mod-groovy > 使用案例 >

Groovy预览--可重写的操作符

慕容修伟
2023-12-01

 

 
Operator  Name  Method  Works with
a + bPlusa.plus(b)Number, String, Collection
a - bMinusa.minus(b)Number, String, Collection
a * bStara.multiply(b)Number, String, Collection
a / bDividea.div(b)Number
a % bModuloa.mod(b)Integral number

a++

++a

Post increment

Pre increment

a.next

Number,String,range

a--

--a

Post decrement

Pre decrement

a.previousNumber,String,range
a **bpowera.power(b)Number
a | bNumerical ora.or(b)Integral number
a  &  bNumerical anda.and(b)Integral number
a ^ bNumerical xora.xor(b)Integral number
-aBitwise complementa.negate()Integral number,String
a[b]Subscripta.getAt(b)Object, list, map, String, Array
a[b]=cSubcript assignmenta.putAt(v,c)Object, list, map, StringBuffer, Array
a << bLeft shifta.leftShift(b)Integral number
a >> bRight shifta.rightShift(b)Integral number
a >>> bRight shift unsigneda.rightShiftUnsigned(b)Integral number

switch(a){

case b:

}

Classificationb.isCase(a)Object, range, list, collection, pattern, closure
a <=> bSpaceshipa.compareTo(b)java.lang.Comparable
a > bGreater thana.compareTo(b) > 0 
a >= bGreater than or equal toa.compareTo(b) >= 0 
a < bLess thana.compareTo(b) < 0 
a <= b Less than or equal toa.compareTo(b) <= 0 
    
    
    

转载于:https://www.cnblogs.com/jyan/archive/2012/05/28/2521429.html

 类似资料: