Example: Count property (JavaMethodCollection class)
This script prints out the number of toString methods belonging to the java.lang.Integer class.
Dim mySession As JavaSession
Dim myClass As JavaClass
Dim myMethod As JavaMethod
Dim myMCollection As JavaMethodCollection
Dim Count As Integer, i As Integer
Set mySession = new JavaSession()
' Get Java "java.lang.Integer" class
Set myClass = mySession.GetClass("java/lang/Integer")
' Get a list of all methods belonging
' to the java.lang.Integer class
Set myMCollection = myClass.getClassMethods()
For i = 1 to myMCollection.Count
Set myMethod = myMCollection.getNth(i)
If myMethod.MethodName = "toString" then
Count = Count + 1
End If
Next
Print "There are " & Count & " instances of toString" + _
"method in the Method collection for java.lang.Integer"
Overloaded methods are also counted.
Sub Initialize
Dim mySession As JavaSession
Dim myClass As JavaClass
Dim myMCollection As JavaMethodCollection
Dim i As Integer
Dim msg As String
Set mySession = New JavaSession()
Set myClass = mySession.GetClass("java/lang/Object")
Set myMCollection = myClass.GetClassMethods()
i = 1
msg = ""
ForAll m In myMCollection
msg = msg & i & " " & m.MethodName & " " & m.Signature & {
}
i = i + 1
End ForAll
MessageBox msg & "Count is " & myMCollection.Count
End Sub
The MessageBox displays
1 getClass ()Ljava/lang/Class;
2 hashCode ()I
3 equals (Ljava/lang/Object;)Z
4 toString ()Ljava/lang/String;
5 notify ()V
6 notifyAll ()V
7 wait (J)V
8 wait (JI)V
9 wait ()V
Count is 9
The last three methods are overloaded.