StackOverflow 文档 groovy 教程 宇宙飞船运算符 Spaceship 运算符进行自定义排序 Spaceship 运算符进行自定义排序 Created: November-22, 2018 class User { String name int age } def users = [ new User(name: "Bob", age: 20), new User(name: "Tom", age: 50), new User(name: "Bill", age: 45) ] // sort by age users.sort { a, b -> a.age <=> b.age } 基本用法宇宙飞船运算符