1

Ok here is my dilemma, I want to create an array of custom objects but then be able to do something like list[index].method call.

as an example:

  • program starts
  • program creates a master array which holds GenericClass< T >(param)
  • each generic class then creates an array of type T

I can get that part to work ok but then when I try to use my object methods such as

object[] MasterList = new object[MASTER_LIST_SIZE]; 
// add contents to MasterList

MasterList[index].setValueAt(MethodIndex, value);

I get a message that reads object has no method named setValueAt which requires one parameter(s)

I will admit that what I am trying to do is rather dumb and I could probably do it easier with reading a text file or something but if there is a way to do it like this I would like to know how or at least what I am missing.

8
  • Why do you get a "no method named setValueAt which requires one parameter" error when you are actually passing two arguments? Commented Sep 27, 2011 at 0:09
  • What is the static type of MasterList? Commented Sep 27, 2011 at 0:11
  • @Everett - I'm gonna take a wild guess and say you are using ArrayList? Commented Sep 27, 2011 at 0:25
  • object[] MasterList = new object[MASTER_LIST_SIZE]; Commented Sep 27, 2011 at 0:38
  • 2
    @Everett - If you know the type of the contents of the array why are you not taking advantage of that fact? Commented Sep 27, 2011 at 0:42

1 Answer 1

3

There are a lot of unknowns about what you are doing but my best guess is that you need to cast the result to the type you need.

((GenericClass<T>)MasterList[index]).setValueAt(MethodIndex, value);
Sign up to request clarification or add additional context in comments.

1 Comment

that got me close enough that I think I can work with it thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.