Problems creating generic classes..

Monkey Forums/Monkey Programming/Problems creating generic classes..

Kauffy(Posted 2013) [#1]
I'm creating a generic AssetList class-- this is basically a managed pool of objects stored in an array.

There is another class for the Assets themselves (that is, the AssetList <classType> is made up of Asset<classType> entries).

Unfortunately, I'm getting that "Wrong number of type arguments for class Asset<classType>" from the line:

		Field _assets:Asset[]


Regardless of whether I declare it that way or

		Field _assets:Asset<classType>[]


What am I doing wrong?


Jesse(Posted 2013) [#2]
does your asset class look like this?:

Class Asset<T>



works fine here:

Import mojo


Function Main:Int()
	Local cl:MyClass = New MyClass
	cl.display()
End Function


Class MyClass

	Field assets:Assets<ThisClass>[]

	Method New()
		assets = New Assets<ThisClass>[5]
		assets[0] = New Assets<ThisClass>
	End Method
	
	Method display()
		assets[0].display()
	End Method

End Class

Class Assets<classType>
	Field test:classType
	
	Method New()
		test = New classType
	End Method
	
	Method display()
		Print test.a+" "+test.b
	End method
End Class


Class ThisClass
	Field a:Int=3
	Field b:Int=4
End Class



Kauffy(Posted 2013) [#3]
Yeah, my class is set up that way-- the one difference is that, per your example,

MyClass would also be MyClass<ThisClass>

Both classes are generics, intended to deal with a given type.




Kauffy(Posted 2013) [#4]
Okay, for some reason, this code is working now. Maybe the issue was with Jungle-- it sometimes reports errors where there used to be errors when other errors exist. :)

In other words, the problem wasn't with the code I thought it was-- it was on another line that had a similar problem, but because the first line had a problem before.

I ~think~ this is fixed now-- and basically, Monkey is behaving as expected.