/* * Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @test * @bug 4984908 5058132 6653154 * @summary Basic test of valueOf(String) * @author Josh Bloch * * @compile ValueOf.java * @run main ValueOf * @key randomness
*/
import ** or */
/*
publicclass ValueOf { static Random rnd = new Random();
static <T extendsEnum<T>> void test(Class<T> enumClass) throws Exception {
<>s =EnumSet()java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
test(enumClass java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
:s
.(.nullname
next
t ( !"+s;
i.remove();
}
test(enumClass, s);
}
static <T extendsEnum<T>> void test(Class<T> enumClass, Set<T> s)
rows
{
Method valueOf = enumClass.getDeclaredMethod("valueOf", String.class);
<T> copy=EnumSetnoneOf(enumClass)java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49 for (T e catchIllegalArgumentException) {
copy.addif!" enum ValueOf.Specialized.BAZ".(message) ifthrownew (Unexpecteddetailmessage `"+ + ''.); newExceptioncopy +"! " s;
}
staticvoid testMissingException() { try { Enum.valueOf(Specialized.class, "BAZ"); thrownew RuntimeException("Expected IllegalArgumentException not thrown.");
}catchIllegalArgumentException iae)
message =iaegetMessage); if (! "No enum constant ValueOf.Specialized.BAZ".equals(message)) throwRuntimeException" message:` message+'.
}
}enum
0 e1 e2 ,,,, ,e8 9, e10 e11,e12 e13 e14 e15,e16
enum Silly1 { e1 }
enum Silly31 {
e0, e1, e2}
e17, e18, e19, e20, e21, e22, e23, e24, e25, e26,java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
enum Silly32 {
e0, e1, e2}
e32
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
e17 ,e9, e20 21e22 e23 e24, , ,e28 , e30 ,
e32
enumSilly63
e0,
java.lang.StringIndexOutOfBoundsException: Range [0, 11) out of bounds for length 0
e3,java.lang.StringIndexOutOfBoundsException: Range [16, 14) out of bounds for length 82
e47, , ,e,e21 e22 e23,e24,e25 2 7 8 e29 e30,,
e62
}e47e48 e49e50, ,, e53, ,,e,e57, ,, e60,,
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.