Object 객체에 대한 GDK 확장
2024 단어 groovy
Object 객체에 대한 GDK 확장
Groovy는
java.lang.Object
에 몇 가지 방법을 추가했는데, 그 중 대부분은 목록이나 DOM 노드와 같은 집합 또는 집합으로 처리된다.Return Value
Method
Description
Boolean
any {closure}
returns
true
if the closure returns true for any item List
collect {closure}
returns a list of all items that were returned from the closure
Collection
collect(Collection collection) {closure}
same as above, but adds each item to the given collection
void
each {closure}
simply executes the closure for each item
void
eachWithIndex {closure}
same as each{} except it passes two arguments: the item and the index
Boolean
every {closure}
returns
true
if the closure returns true
for all items Object
find {closure}
returns the first item that matches the closure expression
List
findAll {closure}
returns all items that match the closure expression
Integer
findIndexOf {closure}
returns the index of the first item that matched the given expression
상기 표에 자주 사용하는 방법만 표시하고
java.lang.Object
에 추가된 완전한 방법 목록은 GDK documentation on Object가 Groovy에서 return
키워드가 선택된 후에 클립은 이 상황에서
로 간주되고 클립에서 어떤 표현식이 나오든지 되돌아오는 결과는 볼형입니다.이런
는 당신이 집합 대상에서 매우 간결한 방식으로 조작을 실행할 수 있도록 한다.예.
def numbers = [ 5, 7, 9, 12 ]
assert numbers.any { it % 2 == 0 } //returns true since 12 is even
assert numbers.every { it > 4 } //returns true since all #s are > 4
assert numbers.findAll { it in 6..10 } == [7,9] //returns all #s > 5 and < 11
assert numbers.collect { ++it } == [6, 8, 10, 13] //returns a new list with each # incremented
numbers.eachWithIndex{ num, idx -> println "$idx: $num" } //prints each index and number
원문 주소http://groovy.codehaus.org/GDK+Extensions+to+Object
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Android Build.Gradle 설명 🌟Gradle은 Android 애플리케이션의 개발 단계를 자동화하는 빌드 시스템입니다. Gradle 시스템에서 Java 플랫폼용 코드를 작성하는 동안 우리는 매우 간단한 언어인 Groovy 프로그래밍 언어를 사용합니다...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.