1

I have some javascript code that looks like this

attachmentFiles.push(fileObj);  

where fileObj is the file user has selected to upload.

Now if I want to represent in the java/json format, what should be the type of the list?

i.e

public class AttachmentHodler{
    List<?> attachmentFiles;


    public List<?> getAttachmentFiles() {
        return attachmentFiles;
    }

    public void setAttachmentFiles(List<?> attachmentFiles) {
        this.attachmentFiles = attachmentFiles;
    }

}
1
  • you misspelled class Commented Jul 30, 2013 at 10:19

2 Answers 2

1

It depends on the purpose of fileObj. Depending on what you want to do with it and what it's responsibilities are you could use:

  • some specialized Attachement class that you would create. Most versatile approach from the OO perspective. Example: http://ideone.com/H23Za7
  • An actual File that supports operation like .delete().
  • just a String to represent the path without any useful functionality.
Sign up to request clarification or add additional context in comments.

Comments

0

It depends on what you want to store in your List. You can even choose to use List<?>, which will allow you to store almost anything in it. But if your attachment objects are of type Attachment, I'do go with List<Attachment>. That would allow you to store only Attachment objects in the list.

Since in Javascript there are no classes, it might be worth to mention that in Java, every object is an instance of a "class". Sometimes you define classes yourself, sometimes you re-use classes inside a framework or library.

So there is no general answer to the question, what type your elements will have.

1 Comment

Sorry ..its the file Object in the javascript which gets pushed to this object ..surely ..it cant have some random type?

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.