Java Object Type Case cast(final Object o)

Here you can find the source of cast(final Object o)

Description

Utility method to perform generic casts without dealing with Unchecked cast warnings (or having to apply SuppressWarnings("unchecked") annotations).

License

BSD License

Parameter

Parameter Description
o Object which is presumably of type T
T type to cast to

Return

the object as instance of T

Declaration

@SuppressWarnings("unchecked")
public static <T> T cast(final Object o) 

Method Source Code

//package com.java2s;
//License from project: BSD License 

public class Main {
    /**//from  w w  w .j a  v a2s  .  c o m
     * Utility method to perform generic casts without dealing with <i>Unchecked cast</i> warnings
     * (or having to apply <code>SuppressWarnings("unchecked")</code> annotations).
     * @param o Object which is presumably of type T
     * @param <T> type to cast to
     * @return the object as instance of T
     */
    @SuppressWarnings("unchecked")
    public static <T> T cast(final Object o) {
        return (T) o;
    }
}

Related

  1. cast(Class type, Object key, Object value)
  2. cast(Class type, Object obj)
  3. cast(double[] arr)
  4. cast(final Class clazz)
  5. cast(final Number number, final Class returnType)
  6. cast(final Object obj, final Class type)
  7. cast(final Object object)
  8. cast(final Object original)
  9. cast(int value)