Here you can find the source of castToShort(Object value)
public static final Short castToShort(Object value)
//package com.java2s; //License from project: Apache License public class Main { public static final Short castToShort(Object value) { if (value == null) { return null; }//ww w . j ava2s.c o m if (value instanceof Number) { return ((Number) value).shortValue(); } if (value instanceof String) { String strVal = (String) value; if (strVal.length() == 0) { return null; } if ("null".equals(strVal) || "NULL".equals(strVal)) { return null; } if (strVal.trim().length() == 0) { return null; } return Short.parseShort(strVal); } throw new NumberFormatException("can not cast to short, value : " + value); } }