例: Count プロパティ (JavaMethodCollection クラス)

次のスクリプトでは、java.lang.Integer クラスに属する toString メソッドの番号が出力されます。

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"

多重定義されたメソッドもカウントされます。

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

MessageBox に次のように表示されます。

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

最後の 3 つのメソッドは多重定義されています。