Here you can find the source of assertInstance(final Object object, final Class c, final boolean allowNull)
null
.
Parameter | Description |
---|---|
object | The object for which the type should be checked. |
c | The class that the object must be; fails if the class is <code>null</code>. |
allowNull | Whether the object being <code>null</code> will not cause a failure. |
public static final void assertInstance(final Object object, final Class c, final boolean allowNull)
//package com.java2s; /******************************************************************************* * Copyright (c) 2000, 2006 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:/*ww w . j av a 2 s. co m*/ * IBM Corporation - initial API and implementation *******************************************************************************/ public class Main { /** * Asserts the the given object is an instance of the given class -- * optionally allowing the object to be <code>null</code>. * * @param object * The object for which the type should be checked. * @param c * The class that the object must be; fails if the class is * <code>null</code>. * @param allowNull * Whether the object being <code>null</code> will not cause a * failure. */ public 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(); } } }