예를 들어, 메소드를 정의했습니다.어떤 언어가 정의 된 매개 변수 이름을 가져오고 매개 변수 이름을 전달할 수 있습니까?
def hello(String name) {
println("Hello " + name)
}
런타임에서 인수의 이름을 원합니다.
def hello(String name) {
println("The name of the parameter of this method is: " + getParamName())
// getParamName() will be `name` here
}
그리고 이 매개 변수의 이름을 전달할 것으로 예상됩니다.
def hello(String name) {
println("Passed parameter name: " + getPassedName())
}
String user1 = "someone"
hello(user1)
다음과 같이 인쇄됩니다.
Passed parameter name: user1
여기서 user1, 변수 이름!
자바/그루비/스칼라가 그렇게 할 수 없기 때문에 이것이 어렵다는 것을 알고 있습니다. 그러나 이것은 매우 유용한 기능이라고 생각합니다 (특히 웹 프레임 워크 디자인의 경우). 언어가 그것을 할 수 있습니까?
당신이 할 수있는 C#, 예를 들어 여기 좀 봐 : http://stackoverflow.com/questions/869610/c-resolving-a-parameter-name-at-runtime – openshac
D는 컴파일해야한다고 시간 반영! 해당 문서 http://dlang.org/traits.html – nawfal