Here you can find the source of assertInstance(final Object object, final Class> c)
Parameter | Description |
---|---|
object | The object to check; may be <code>null</code>. |
c | The class which the object should be; must not be <code>null</code>. |
public static final void assertInstance(final Object object, final Class<?> c)
//package com.java2s; /******************************************************************************* * Copyright (c) 2013, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w ww.j a v a 2 s . co m*/ * IBM Corporation - initial API and implementation *******************************************************************************/ public class Main { /** * Verifies that the given object is an instance of the given class. * * @param object * The object to check; may be <code>null</code>. * @param c * The class which the object should be; must not be <code>null</code>. */ public static final void assertInstance(final Object object, final Class<?> c) { assertInstance(object, c, false); } /** * Verifies the given object is an instance of the given class. It is possible to specify * whether the object is permitted to be <code>null</code>. * * @param object * The object to check; may be <code>null</code>. * @param c * The class which the object should be; must not be <code>null</code>. * @param allowNull * Whether the object is allowed to be <code>null</code>. */ private static final void assertInstance(final Object object, final Class<?> c, final boolean allowNull) { if (object == null && allowNull) { return; } if (object == null || c == null) { throw new NullPointerException(); } else if (!c.isInstance(object)) { throw new IllegalArgumentException(); } } }