Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

my code is as below...

@ResponseBody 
@RequestMapping(value ="/updateAll", method=RequestMethod.POST)  
public JSONObject update( @RequestBody List<T> list){ 
    try{
        T entity = list.get(0);
        System.out.println(entity.getClass());
        dbService.update(entityName + ".update", list);
        return jsonResult(null, null, null, 0);
    }catch(Exception ex){
        return jsonResult(null, null, ex, 0);
    }
}

It returns an proper object name when I get only one entity through @RequestBody, but the code above returns java.util.LinkedHashMap which i cannot use the merit of parameterClass in iBatis. (sorry for my poor english... )

I cast again the list to T , but still it returns LinkedHashMap.

isn't the code [ T entity = list.get(0); ] means it recognize the list as the collection of object T ?

@ResponseBody 
@RequestMapping(value ="/updateAll", method=RequestMethod.POST)  
public JSONObject update( @RequestBody T entity){ 
    try{
        System.out.println(entity.getClass());
        dbService.update(entityName + ".update", entity);
        return jsonResult(null, null, null, 0);
    }catch(Exception ex){
        return jsonResult(null, null, ex, 0);
    }
}

This prints the entity name exactly without any problem.

Can anybody explain me why this happen? where I can learn more about this?

share|improve this question

1 Answer 1

up vote 0 down vote accepted
 /**
     * Returns the runtime class of this {@code Object}. The returned
     * {@code Class} object is the object that is locked by {@code
     * static synchronized} methods of the represented class.
     *
     * <p><b>The actual result type is {@code Class<? extends |X|>}
     * where {@code |X|} is the erasure of the static type of the
     * expression on which {@code getClass} is called.</b> For
     * example, no cast is required in this code fragment:</p>
     *
     * <p>
public final native Class<?> getClass();

It doesn't matter what reference type is . Method getClass() returns runtime class.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.