List of usage examples for java.lang Object getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:Main.java
public static void main(String[] args) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(Home.class, Person.class, Animal.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); StreamSource xml = new StreamSource("input.xml"); Home home = unmarshaller.unmarshal(xml, Home.class).getValue(); for (Object object : home.any) { System.out.println(object.getClass()); }/*from ww w. j a va2 s .co m*/ }
From source file:AllFieldsSnippet.java
public static void main(String[] args) { Object obj = new Object(); //start extract AllFieldsSnippet Class cls = obj.getClass(); List accum = new LinkedList(); while (cls != null) { Field[] f = cls.getDeclaredFields(); for (int i = 0; i < f.length; i++) { accum.add(f[i]);/* w w w . j a v a2 s . c o m*/ } cls = cls.getSuperclass(); } Field[] allFields = (Field[]) accum.toArray(new Field[accum.size()]); //stop extract AllFieldsSnippet }
From source file:Main.java
public static void main(String[] args) throws Exception { Object clazz = new TestClass(); String lookingForValue = "firstValue"; Field field = clazz.getClass().getField(lookingForValue); Class clazzType = field.getType(); if (clazzType.toString().equals("double")) System.out.println(field.getDouble(clazz)); else if (clazzType.toString().equals("int")) System.out.println(field.getInt(clazz)); //System.out.println(field.get(clazz)); }
From source file:FormattedSample.java
public static void main(final String args[]) { JFrame frame = new JFrame("Formatted Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DateFormat displayFormat = new SimpleDateFormat("yyyy--MMMM--dd"); DateFormatter displayFormatter = new DateFormatter(displayFormat); DateFormat editFormat = new SimpleDateFormat("MM/dd/yy"); DateFormatter editFormatter = new DateFormatter(editFormat); DefaultFormatterFactory factory = new DefaultFormatterFactory(displayFormatter, displayFormatter, editFormatter);/*from ww w. j a va 2 s . c o m*/ JFormattedTextField date2TextField = new JFormattedTextField(factory, new Date()); frame.add(date2TextField, BorderLayout.NORTH); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JFormattedTextField source = (JFormattedTextField) actionEvent.getSource(); Object value = source.getValue(); System.out.println("Class: " + value.getClass()); System.out.println("Value: " + value); } }; date2TextField.addActionListener(actionListener); frame.add(new JTextField(), BorderLayout.SOUTH); frame.setSize(250, 100); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Formatted Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DateFormat displayFormat = new SimpleDateFormat("yyyy--MMMM--dd"); DateFormatter displayFormatter = new DateFormatter(displayFormat); DateFormat editFormat = new SimpleDateFormat("MM/dd/yy"); DateFormatter editFormatter = new DateFormatter(editFormat); DefaultFormatterFactory factory = new DefaultFormatterFactory(displayFormatter, displayFormatter, editFormatter);//from ww w . j a va2 s. c o m JFormattedTextField date2TextField = new JFormattedTextField(factory, new Date()); frame.add(date2TextField, BorderLayout.NORTH); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JFormattedTextField source = (JFormattedTextField) actionEvent.getSource(); Object value = source.getValue(); System.out.println("Class: " + value.getClass()); System.out.println("Value: " + value); } }; date2TextField.addActionListener(actionListener); frame.add(new JTextField(), BorderLayout.SOUTH); frame.setSize(250, 100); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps")); DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType()); StreamPrintService service = factories[0].getPrintService(fos); Class[] cats = service.getSupportedAttributeCategories(); for (int j = 0; j < cats.length; j++) { Attribute attr = (Attribute) service.getDefaultAttributeValue(cats[j]); if (attr != null) { String attrName = attr.getName(); String attrValue = attr.toString(); Object o = service.getSupportedAttributeValues(attr.getCategory(), null, null); if (o.getClass().isArray()) { for (int k = 0; k < Array.getLength(o); k++) { Object o2 = Array.get(o, k); System.out.println(o2); }/* ww w.j av a 2 s . c o m*/ } } } }
From source file:com.everm.propertydescriptor.App.java
/** * @param args//from w ww .j a va 2 s. com */ public static void main(String[] args) { try { Object bean = new App(); PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(bean); Class beanClass = bean.getClass(); for (int i = 0; i < pds.length; i++) { String key = pds[i].getName(); Class type = pds[i].getPropertyType(); if (pds[i].getReadMethod() != null) { Object value = PropertyUtils.getProperty(bean, key); } else { String warning = "Property '" + key + "' has no read method. SKIPPED"; } } } catch (Exception e) { e.printStackTrace(); } }
From source file:A.java
public static void main(String[] args) { Main cls = new Main(); Class c = cls.getClass();//w ww . ja v a 2 s . c o m System.out.println(c); Object obj = new A(); B b1 = new B(); b1.show(); // casts object Object a = A.class.cast(b1); System.out.println(obj.getClass()); System.out.println(b1.getClass()); System.out.println(a.getClass()); }
From source file:Main.java
public static void main(String[] argv) { DefaultTableModel model = new DefaultTableModel() { public Class getColumnClass(int columnIndex) { Object o = getValueAt(0, columnIndex); if (o == null) { return Object.class; } else { return o.getClass(); }/* w w w. ja v a 2 s .co m*/ } }; JTable table = new JTable(model); model.addColumn("Boolean", new Object[] { Boolean.TRUE }); model.addColumn("Date", new Object[] { new Date() }); model.addColumn("Double", new Object[] { new Double(Math.PI) }); model.addColumn("Float", new Object[] { new Float(1.2) }); model.addColumn("Icon", new Object[] { new ImageIcon("icon.gif") }); model.addColumn("Number", new Object[] { new Integer(1) }); model.addColumn("Object", new Object[] { "object" }); JFrame f = new JFrame(); f.setSize(300, 300); f.add(new JScrollPane(table)); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps")); DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType()); StreamPrintService service = factories[0].getPrintService(fos); Class category = OrientationRequested.class; Object o = service.getSupportedAttributeValues(category, null, null); if (o == null) { System.out.println("Attribute is not supported"); } else if (o.getClass() == category) { System.out.println("irrelevant"); } else if (o.getClass().isArray()) { System.out.println("array"); for (int i = 0; i < Array.getLength(o); i++) { Object v = Array.get(o, i); System.out.println(v); }//w ww. j av a 2s .c om } }