1 /******************************************************************************* 2 * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors 3 * This program and the accompanying materials are made available under 4 * the terms of the Eclipse Public License 2.0 which is available at 5 * http://www.eclipse.org/legal/epl-2.0 6 * 7 * SPDX-License-Identifier: EPL-2.0 8 * 9 * Contributors: 10 * Evgeny Mandrikov - initial API and implementation 11 * 12 *******************************************************************************/ 13 package org.jacoco.core.test.validation.java14.targets; 14 15 import static org.jacoco.core.test.validation.targets.Stubs.nop; 16 17 /** 18 * This target exercises pattern matching for instanceof (JEP 305). 19 */ 20 public class InstanceofTarget { 21 ifInstanceof(Object e)22 private static void ifInstanceof(Object e) { 23 if (e instanceof String s) { // assertInstanceof() 24 nop(s); 25 } 26 } 27 main(String[] args)28 public static void main(String[] args) { 29 ifInstanceof(new Object()); 30 ifInstanceof("string"); 31 } 32 33 } 34