< prev index next >

test/langtools/tools/javac/switchexpr/LambdaCapture.java

Print this page
rev 56806 : 8232684: Make switch expressions final
Reviewed-by: TBD


   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8220041
  27  * @summary Verify variable capture works inside switch expressions which are
  28  *          inside variable declarations
  29  * @compile --enable-preview -source ${jdk.version} LambdaCapture.java
  30  */
  31 
  32 import java.util.Objects;
  33 
  34 public class LambdaCapture {
  35     public static void main(String... args) {
  36         new LambdaCapture().run();
  37     }
  38 
  39     void run() {
  40         assertEquals("00", lambdaCapture1(0).t());
  41         assertEquals("12", lambdaCapture1(1).t());
  42         assertEquals("D", lambdaCapture1(2).t());
  43         assertEquals("D", lambdaCapture1(3).t());
  44         assertEquals("00", lambdaCapture2(0).t());
  45         assertEquals("12", lambdaCapture2(1).t());
  46         assertEquals("D", lambdaCapture2(2).t());
  47         assertEquals("D", lambdaCapture2(3).t());
  48     }
  49 




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8220041
  27  * @summary Verify variable capture works inside switch expressions which are
  28  *          inside variable declarations
  29  * @compile LambdaCapture.java
  30  */
  31 
  32 import java.util.Objects;
  33 
  34 public class LambdaCapture {
  35     public static void main(String... args) {
  36         new LambdaCapture().run();
  37     }
  38 
  39     void run() {
  40         assertEquals("00", lambdaCapture1(0).t());
  41         assertEquals("12", lambdaCapture1(1).t());
  42         assertEquals("D", lambdaCapture1(2).t());
  43         assertEquals("D", lambdaCapture1(3).t());
  44         assertEquals("00", lambdaCapture2(0).t());
  45         assertEquals("12", lambdaCapture2(1).t());
  46         assertEquals("D", lambdaCapture2(2).t());
  47         assertEquals("D", lambdaCapture2(3).t());
  48     }
  49 


< prev index next >