Age over 28 [Groovy]

  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.
  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.
class Person {
  String name
  Integer age
}
 
john = new Person(name:'John', age:30)
mary = new Person(name:'Mary', age:25)
 
assert [john] == [john, mary].grep{it.age > 28}

grep!!! สำหรับคนชอบ command line

veer's picture

ตอนสร้าง object ดูได้อย่างใจดี (แต่ว่าตอนสร้าง class ต้องระบุ type ก็อาจจะดี แต่ว่าขี้เกียจใส่จัง :-P)

ไม่ต้องระบุก็ได้ครับ

class Person {
  def name
  def age
}
 
john = new Person(name:'John', age:30)
mary = new Person(name:'Mary', age:25)
 
assert [john] == [john, mary].grep{it.age > 28}

ติดจาก Java เพราะ type ของ class นี้ค่อนข้างชัดเจน

veer's picture

แบบนี้เจ๋ง :-D

sugree's picture

groovy งามมาก ว่าแต่ตอนรันมันใช้แรมเยอะมั๊ยครับ

veer's picture

ผมกะจะซื้อเพิ่มซัก 1 GB ละ :-P (คงต้องออกมาแนวนี้แทน)

ห่วงแต่แบบ JDK มัน initialize ช้าทำไรใน shell ยากจัง T_T

ย้าย Codenone

ประกาศย้าย Codenone ไปใช้ Forum ของ Blognone แทนครับ ตามไปตั้งกระทู้ต่อได้ที่ Codenone Forum (รายละเอียดอ่านจากกระทู้ ย้าย Codenone ไปรวมกับ Blognone)

กระทู้เก่าๆ จะย้ายตามไปในภายหลัง ตอนนี้ปิดการโพสต์กระทู้ไว้ เหลือไว้เฉพาะอ้างอิงเท่านั้น