Convert Object to List

I have a method takes a Object and I need to convert it to List. What is the best way to do that?

The same way you convert a thing to an apple.
Either the thing is an apple, then you can help yourself by calling it "apple" instead of "thing" (namely casting the handling reference to the type "apple" --> Apple a = (Apple) theThing; ), or it isn't an apple at all and there's nothing you can do about it.
If you cast, please do an instanceof check first. But I'd rather suggest passing List-type arguments right away if you can.

Similar Messages

  • Cannot Cast List ? extends Object as List Object

    I apologize if this is a common question but I could not seem to find the proper set of search terms that yielded an answer.
    Basically I have an RMI application and on the 'middle-tier' I would like to pass around references to the implementation objects and only convert to the interface type when dealing with them over RMI (I never pass an object back to the middle-tier).
    public interface Questionnaire implements Remote {
        public List<? extends Comment> getComments() throws RemoteException;
    public class QuestionnaireImpl extends UnicastRemoteObject implements Questionnaire {
        public List<CommentImpl> getComments() {...}
    }This works fine, the issue arises when I try to do the following:
    public List<Comment> getComments(int questionnaireId) throws RemoteException {
        return classLoader.getQuestionnaire(questionnaireId).getComments();
    }The compiler issues a Type mismatch: cannot convert from List<capture#8-of ? extends Comment> to List<Comment> Which I find perplexing as the compiler can assure that at the very least it is a List of Comment objects.

    public List<? extends Comment> getComments() throws RemoteException;
    public List<Comment> getComments(int questionnaireId) throws RemoteException {
    return classLoader.getQuestionnaire(questionnaireId).getComments();
    The compiler issues a Type mismatch: cannot convert from List<capture#8-of ? extends Comment> to List<Comment> Which I find perplexing as the compiler can assure that at the very least it is a List of Comment objects.Yes, however Java's generics work correctly to prevent you from shooting yourself in the foot. If you have a List<Superclass> pointing at a List<Subclass>, you would be entirely within your rights to try to store an object that is not castable to Subclass in it, this breaks type safety, so the compiler will not let you do it.
    Instead, create a new List<Supertype> and copy over the elements from the list returned by getComments(). There is a constructor that will do this for you.

  • What is the problem with converting objects with gradients to gradient mesh?

    What is the problem with converting objects with gradients to gradient mesh?

    slange,
    There may arise some smaller corruption states that may be cured by what you did, as you can see in the list. Sometimes, restarting thrice is needed.
    The following is a general list of things you may try when the issue is not in a specific file (you may have tried/done some of them already); 1) and 2) are the easy ones for temporary strangenesses, and 3) and 4) are specifically aimed at possibly corrupt preferences); 5) is a list in itself, and 6) is the last resort.
    If possible/applicable, you should save curent artwork first, of course.
    1) Close down Illy and open again;
    2) Restart the computer (you may do that up to 3 times);
    3) Close down Illy and press Ctrl+Alt+Shift/Cmd+Option+Shift during startup (easy but irreversible);
    4) Move the folder (follow the link with that name) with Illy closed (more tedious but also more thorough and reversible);
    5) Look through and try out the relevant among the Other options (follow the link with that name, Item 7) is a list of usual suspects among other applications that may disturb and confuse Illy, Item 15) applies to CC, CS6, and maybe CS5);
    Even more seriously, you may:
    6) Uninstall, run the Cleaner Tool (if you have CS3/CS4/CS5/CS6/CC), and reinstall.
    http://www.adobe.com/support/contact/cscleanertool.html

  • How can i convert object to byte array very*100 fast?

    i need to transfer a object by datagram packet in embeded system.
    i make a code fallowing sequence.
    1) convert object to byte array ( i append object attribute to byte[] sequencailly )
    2) send the byte array by datagram packet ( by JNI )
    but, it's not satisfied my requirement.
    it must be finished in 1ms.
    but, converting is spending 2ms.
    network speed is not bottleneck. ( transfer time is 0.3ms and packet size is 4096 bytes )
    Using ObjectOutputStream is very slow, so i'm using this way.
    is there antoher way? or how can i improve?
    Edited by: JongpilKim on May 17, 2009 10:48 PM
    Edited by: JongpilKim on May 17, 2009 10:51 PM
    Edited by: JongpilKim on May 17, 2009 10:53 PM

    thanks a lot for your reply.
    now, i use udp socket for communication, but, i must use hardware pci communication later.
    so, i wrap the communication logic to use jni.
    for convert a object to byte array,
    i used ObjectInputStream before, but it was so slow.
    so, i change the implementation to use byte array directly, like ByteBuffer.
    ex)
    public class ByteArrayHelper {
    private byte[] buf = new byte[1024];
    int idx = 0;
    public void putInt(int val){
    buf[idx++] = (byte)(val & 0xff);
    buf[idx++] = (byte)((val>>8) & 0xff);
    buf[idx++] = (byte)((val>>16) & 0xff);
    buf[idx++] = (byte)((val>>24) & 0xff);
    public void putDouble(double val){ .... }
    public void putFloat(float val){ ... }
    public byte[] toByteArray(){ return this.buf; }
    public class PacketData {
    priavte int a;
    private int b;
    public byte[] getByteArray(){
    ByteArrayHelper helper = new ByteArrayHelper();
    helper.putInt(a);
    helper.putInt(b);
    return helper.toByteArray();
    but, it's not enough.
    is there another way to send a object data?
    in java language, i can't access memory directly.
    in c language, if i use struct, i can send struct data to copy memory by socket and it's very fast.
    Edited by: JongpilKim on May 18, 2009 5:26 PM

  • Services for Objects Attachement List Display Note not Viewable

    Hi Experts!
    Good day! I'm trying to display a note in FK03 (related to Services for Objects - Attachment List) and I only see white screen pop up window. No message and text information. When I tried to use another PC I can successfully view it.
    Is there's a plugin that I may need to install?
    Your help will be greatly appreciated.

    Hi Marty
    It is my understanding that the IXOS licensing is based on users retrieving of documents not necessarily the viewer so the licensing implications of having non-IXOS viewers accessing documents using the generic archivelink viewer is still likely to result in licensing implications if an audit is conducted at any stage.
    The transaction for specifying the viewer is the OAA3 and OAG4.
    Regards,
    Athol

  • How to convert the alv list data into pdf format

    Hi Expersts,
                      Is it possible to convert the alv list output data into PDF format? if yes, then please help me with this issue.
    thanks in advance,
    Regards,
    Samad

    hii samad,
    you can go through these link.i hope it ll solve your purpose
    How to convert list output to PDF
    Display ALV list output in PDF format
    regards,
    Shweta

  • Converting object wrapper type array into equivalent primary type array

    Hi All!
    My question is how to convert object wrapper type array into equivalent prime type array, e.g. Integer[] -> int[] or Float[] -> float[] etc.
    Is sound like a trivial task however the problem is that I do not know the type I work with. To understand what I mean, please read the following code -
    //Method signature
    Object createArray( Class clazz, String value ) throws Exception;
    //and usage should be as follows:
    Object arr = createArray( Integer.class, "2%%3%%4" );
    //"arr" will be passed as a parameter of a method again via reflection
    public void compute( Object... args ) {
        a = (int[])args[0];
    //or
    Object arr = createArray( Double.class, "2%%3%%4" );
    public void compute( Object... args ) {
        b = (double[])args[0];
    //and the method implementation -
    Object createArray( Class clazz, String value ) throws Exception {
         String[] split = value.split( "%%" );
         //create array, e.g. Integer[] or Double[] etc.
         Object[] o = (Object[])Array.newInstance( clazz, split.length );
         //fill the array with parsed values, on parse error exception will be thrown
         for (int i = 0; i < split.length; i++) {
              Method meth = clazz.getMethod( "valueOf", new Class[]{ String.class });
              o[i] = meth.invoke( null, new Object[]{ split[i] });
         //here convert Object[] to Object of type int[] or double[] etc...
         /* and return that object*/
         //NB!!! I want to avoid the following code:
         if( o instanceof Integer[] ) {
              int[] ar = new int[o.length];
              for (int i = 0; i < o.length; i++) {
                   ar[i] = (Integer)o;
              return ar;
         } else if( o instanceof Double[] ) {
         //...repeat "else if" for all primary types... :(
         return null;
    Unfortunately I was unable to find any useful method in Java API (I work with 1.5).
    Did I make myself clear? :)
    Thanks in advance,
    Pavel Grigorenko

    I think I've found the answer myself ;-)
    Never thought I could use something like int.class or double.class,
    so the next statement holds int[] q = (int[])Array.newInstance( int.class, 2 );
    and the easy solution is the following -
    Object primeArray = Array.newInstance( token.getPrimeClass(), split.length );
    for (int j = 0; j < split.length; j++) {
         Method meth = clazz.getMethod( "valueOf", new Class[]{ String.class });
         Object val = meth.invoke( null, new Object[]{ split[j] });
         Array.set( primeArray, j, val );
    }where "token.getPrimeClass()" return appropriate Class, i.e. int.class, float.class etc.

  • Converting Object to a Date

    Hey guys some one help me out..
    1) How to convert Object to Date and
    2) Date to a String in a specified format like "MM : DDD : YYYY".
    Thanks in Advance :-)

    Thanks guys.. I got it.

  • UnsupportedOperationException Error while removing object from List

    Hi,
    I need to remove a set of objects from List if it contains similar objects as the other one.
    Follwing is the code snippet of the above scenario...
    List selectedPaxList = new ArrayList();
    TreeSet seatAssignedPaxlist= new TreeSet();
    selectedPaxList.add("1");
    selectedPaxList.add("2");
    selectedPaxList.add("3");
    seatAssignedPaxlist.add("1");
    seatAssignedPaxlist.add("2");
    if(selectedPaxList.containsAll(seatAssignedPaxlist))
    selectedPaxList.removeAll(seatAssignedPaxlist);
    If i do this in java program it executes fine without any error.But if I do the same in JSP I am getting the following error......
    java.lang.UnsupportedOperationException
    at java.util.AbstractList.remove(AbstractList.java:167)
    at java.util.AbstractList$Itr.remove(AbstractList.java:432)
    at java.util.AbstractCollection.removeAll(AbstractCollection.java:351)
    Plz... help me to resolve the issue

    java.lang.UnsupportedOperationException
    at
    java.util.AbstractList.remove(AbstractList.java:167)
    at
    java.util.AbstractList$Itr.remove(AbstractList.java:43
    2)
    at
    java.util.AbstractCollection.removeAll(AbstractCollect
    ion.java:351)
    That stack trace looks wrong to me.
    ArrayList overrides the remove method, so it
    shouldn't be using the method in AbstractList. That's what I thought, too. There is either something missing or it's not an ArrayList. In fact the javadoc of AbstractList.remove sais:
    "This implementation always throws an UnsupportedOperationException."
    So it really looks like another subclass is used.
    Also
    the object it is trying to remove is a list (from
    your exmaple it should be a String)
    I could be wrong.These are just the code references not the parameters, I think.
    -Puce

  • Converting enumerations to lists with generics

    hello...
    i want to list off system properties and sort them.
    how can you convert enumerations to lists with generics?
    i tried the following in eclipse, but it fails...
         Properties properties = System.getProperties( ) ;
         Enumeration<?> enumeration = properties.propertyNames( ) ;
         ArrayList<String> arrayListEnum = Collections.list( enumeration ) ;
         Collections.sort( arrayListEnum ) ;

    Because the type parameter of Enumeration (<?>) is not compatible with the type parameter of ArrayList (<String>).
    You'll have to do some manual casting yourself.
    Unfortunately, there's nothing to guarantee that system property keys or values are strings (hence why Enumeration<?> and no Enumeration<String>) so you'll need to cope if you find one that isn't.

  • Is there a way to add new objects to object changeability list?

    My production system is locked and I need to change object type RSFO (formula). I looked at the object changeability list and it does not contain RSFO. Is there a way to add this object to this list so I can change it directly in production? Thanks.

    hi,
    I hope you can create similar formula in the production. as in the production we can change the reports,proces chain,aggregates, infopackages.
    Ramesh

  • Adding objects to list

    Hi,
    I am new java. I have a probelm adding objects to list. This is the following code.
    class Test{
    List <>dataList = new ArrayList<>();
    public List<A> getAList(){
    dataList.add(new A());
    return dataList ;
    public List<B> getBList(){
    dataList.add(new B());
    return dataList;
    }In the above code what I will pass<parameterized data> to the dataList decalred as member variable?

    bhanu wrote:
    nothing common for A and B. Both A and B are different pojos. but we can tell A and B extends from Object.I tried like that
    way. But it is not working. <? extends from Object>.Both two methods have to be in the same classYou do in that case have a bad design. Why is the same list used for both. It can't be type safe so you need to cast and the user of the list might get classcast exceptions during iteration.
    Kaj

  • When can we expect a patch for Object Array List Data Provider?

    Hey JSC Team!
    When can we expect maybe, just maybe a minor patch for the Object Array List Data Provider loading class problem? Next Month? This Year? Next Year? Near Future? Long in the future? Sometime in the 22nd century?

    I think one of the problem is
    when u declare the ObjectListDataProvider in ur backing bean
    it doesnt appear in the design time straight away
    u have to clean build close and re open the project
    which is quite time consuming.

  • Converting object libraries vi command line

    Forms, ifbld60.exe, allows you to create Forms, Libraies, Menus, and Object Libraries. It alsow allows you to convert each type from binary-to-text and back. I have been successful in using ifcmp60.exe to convert FORMS, LIBRARIES, and MENUS from binary-to-text and back.
    How can I also convert Object Libries using ifcmp60.exe?

    I should add that the documented types for ifcmp60.exe are FORM, LIBRARY, MENU and PECS. Don't understand PECS, but I get errors when tring to convert using any of these module_type(s).

  • Add file types to convert to pdf list

    Using Acrobat pro 8.1.2 on Windows XP sp2. When I try to convert to pdf from doc or xls file I get an error message saying "not a supported file type". I checked the prefernces and noted that Microsoft Office is not included in the convert to pdf list. So how do I add Microsoft Office to the list?

    First which version of MS Office are you using?
    In MS Office does the PDF Maker work?
    Have you enabled PDF Maker in MS Office?
    MS Office does not automatically allow PDF Maker macros to work by default. One has to enabale the PDF Maker macros.
    The PDF Maker macros may not recognize the new MS Office file types, so you will have to save your files to the Office 2003/XP types.

Maybe you are looking for

  • File handling issue

    Dear All, I have 1 test program say ZTEST, The above prog is sending data to application server. The file path is like 'path /usr/sap/tmp/ZFILE.txt' I have 2 files, first file contains data like 1 2 3 Second file contains data like A B C If I execute

  • Multiple safari pages

    I have a problem when a hyperlink opens a new page. When I close the new page and go back to the original (where the hyperlink was), the page refreshes and goes to the page that previously opened in a new window. I also can't use the back button when

  • CS 6: trial version install hangs at 42%  (Win 7)

    Greetings, I am attempting to install the CS6 trial version on my Windows 7 machine. When it starts installing AdobeHelp, it gets to 42%, then the time remaining increases, but the percentage stays at 42%. I rebooted and tried again, with the same re

  • Flash intro newbie

    I don't know if this belongs in flash or dreamweaver, so I'm posting it in both places. I have a quicktime movie (originally a motion movie) that I converted into flash video in hopes of using it as an intro to a webpage created with dreamweaver. It

  • Premier CS5.5 Keyboard Shortcuts

    Good morning all, I upgraded to cs5.5 last week, and can't find, "Razor at current time Possition" like I could in CS5. Any ideas? Thanks Paul.