Reflection/List properties: Difference between revisions
Content deleted Content added
Walterpachl (talk | contribs) m →{{header|REXX}}: remove 2 "'" |
Scala contribution added. |
||
Line 556: | Line 556: | ||
p Foo.class_variables #=> [:@@xyz, :@@abc]</lang> |
p Foo.class_variables #=> [:@@xyz, :@@abc]</lang> |
||
=={{header|Scala}}== |
|||
===Java Interoperability=== |
|||
{{Out}}Best seen running in your browser [https://scastie.scala-lang.org/PYo43XQwT4atvLtzNfvY3g Scastie (remote JVM)]. |
|||
<lang Scala>object ListProperties extends App { |
|||
private val obj = new { |
|||
val examplePublicField: Int = 42 |
|||
private val examplePrivateField: Boolean = true |
|||
} |
|||
private val clazz = obj.getClass |
|||
println("All public methods (including inherited):") |
|||
clazz.getFields.foreach(f => println(s"${f}\t${f.get(obj)}")) |
|||
println("\nAll declared fields (excluding inherited):") |
|||
clazz.getDeclaredFields.foreach(f => println(s"${f}}")) |
|||
⚫ | |||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
Tcl objects do not have properties exactly (externally visible variables), though a common idiom pioneered by <b>Tk</b> is <i>options</i> exposed by the <tt>configure</tt> and <tt>cget</tt> commands. |
Tcl objects do not have properties exactly (externally visible variables), though a common idiom pioneered by <b>Tk</b> is <i>options</i> exposed by the <tt>configure</tt> and <tt>cget</tt> commands. |
||
For objects supporting this protocol, you can list all options by invoking the <tt>configure</tt> method without arguments (result split over multiple lines for readability): |
For objects supporting this protocol, you can list all options by invoking the <tt>configure</tt> method without arguments (result split over multiple lines for readability): |
||
<lang Tcl>% package require Tk |
<lang Tcl>% package require Tk |
||
8.6.5 |
8.6.5 |
||
Line 579: | Line 594: | ||
<lang Tcl>% lmap o [. configure] {if {[llength $o] == 2} continue else {lindex $o 0}} |
<lang Tcl>% lmap o [. configure] {if {[llength $o] == 2} continue else {lindex $o 0}} |
||
-borderwidth -class -menu -relief -screen -use -background -colormap -container -cursor -height |
-borderwidth -class -menu -relief -screen -use -background -colormap -container -cursor -height |
||
-highlightbackground -highlightcolor -highlightthickness -padx -pady -takefocus -visual -width |
-highlightbackground -highlightcolor -highlightthickness -padx -pady -takefocus -visual -width</lang> |
||
⚫ | |||
=={{header|zkl}}== |
=={{header|zkl}}== |