Skip to content

Commit 40e07a7

Browse files
committedOct 26, 2024
8342865: Use type parameter for Class::getPrimitiveClass
Reviewed-by: darcy
1 parent 9e451aa commit 40e07a7

File tree

10 files changed

+13
-22
lines changed

10 files changed

+13
-22
lines changed
 

‎src/java.base/share/classes/java/lang/Boolean.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ public final class Boolean implements java.io.Serializable,
7878
*
7979
* @since 1.1
8080
*/
81-
@SuppressWarnings("unchecked")
82-
public static final Class<Boolean> TYPE = (Class<Boolean>) Class.getPrimitiveClass("boolean");
81+
public static final Class<Boolean> TYPE = Class.getPrimitiveClass("boolean");
8382

8483
/**
8584
* The value of the Boolean.

‎src/java.base/share/classes/java/lang/Byte.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ public final class Byte extends Number implements Comparable<Byte>, Constable {
7979
* The {@code Class} instance representing the primitive type
8080
* {@code byte}.
8181
*/
82-
@SuppressWarnings("unchecked")
83-
public static final Class<Byte> TYPE = (Class<Byte>) Class.getPrimitiveClass("byte");
82+
public static final Class<Byte> TYPE = Class.getPrimitiveClass("byte");
8483

8584
/**
8685
* Returns a new {@code String} object representing the

‎src/java.base/share/classes/java/lang/Character.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ class Character implements java.io.Serializable, Comparable<Character>, Constabl
232232
*
233233
* @since 1.1
234234
*/
235-
@SuppressWarnings("unchecked")
236-
public static final Class<Character> TYPE = (Class<Character>) Class.getPrimitiveClass("char");
235+
public static final Class<Character> TYPE = Class.getPrimitiveClass("char");
237236

238237
/*
239238
* Normative general types

‎src/java.base/share/classes/java/lang/Class.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -3278,10 +3278,10 @@ ProtectionDomain protectionDomain() {
32783278
private native ProtectionDomain getProtectionDomain0();
32793279

32803280
/*
3281-
* Return the Virtual Machine's Class object for the named
3282-
* primitive type.
3281+
* Returns the Class object for the named primitive type. Type parameter T
3282+
* avoids redundant casts for trusted code.
32833283
*/
3284-
static native Class<?> getPrimitiveClass(String name);
3284+
static native <T> Class<T> getPrimitiveClass(String name);
32853285

32863286
/*
32873287
* Check if client is allowed to access members. If access is denied,

‎src/java.base/share/classes/java/lang/Double.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,7 @@ public final class Double extends Number
459459
*
460460
* @since 1.1
461461
*/
462-
@SuppressWarnings("unchecked")
463-
public static final Class<Double> TYPE = (Class<Double>) Class.getPrimitiveClass("double");
462+
public static final Class<Double> TYPE = Class.getPrimitiveClass("double");
464463

465464
/**
466465
* Returns a string representation of the {@code double}

‎src/java.base/share/classes/java/lang/Float.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ public final class Float extends Number
175175
*
176176
* @since 1.1
177177
*/
178-
@SuppressWarnings("unchecked")
179-
public static final Class<Float> TYPE = (Class<Float>) Class.getPrimitiveClass("float");
178+
public static final Class<Float> TYPE = Class.getPrimitiveClass("float");
180179

181180
/**
182181
* Returns a string representation of the {@code float}

‎src/java.base/share/classes/java/lang/Integer.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ public final class Integer extends Number
9595
*
9696
* @since 1.1
9797
*/
98-
@SuppressWarnings("unchecked")
99-
public static final Class<Integer> TYPE = (Class<Integer>) Class.getPrimitiveClass("int");
98+
public static final Class<Integer> TYPE = Class.getPrimitiveClass("int");
10099

101100
/**
102101
* All possible chars for representing a number as a String

‎src/java.base/share/classes/java/lang/Long.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ public final class Long extends Number
9595
*
9696
* @since 1.1
9797
*/
98-
@SuppressWarnings("unchecked")
99-
public static final Class<Long> TYPE = (Class<Long>) Class.getPrimitiveClass("long");
98+
public static final Class<Long> TYPE = Class.getPrimitiveClass("long");
10099

101100
/**
102101
* Returns a string representation of the first argument in the

‎src/java.base/share/classes/java/lang/Short.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ public final class Short extends Number implements Comparable<Short>, Constable
7979
* The {@code Class} instance representing the primitive type
8080
* {@code short}.
8181
*/
82-
@SuppressWarnings("unchecked")
83-
public static final Class<Short> TYPE = (Class<Short>) Class.getPrimitiveClass("short");
82+
public static final Class<Short> TYPE = Class.getPrimitiveClass("short");
8483

8584
/**
8685
* Returns a new {@code String} object representing the

‎src/java.base/share/classes/java/lang/Void.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -39,8 +39,7 @@ class Void {
3939
* The {@code Class} object representing the pseudo-type corresponding to
4040
* the keyword {@code void}.
4141
*/
42-
@SuppressWarnings("unchecked")
43-
public static final Class<Void> TYPE = (Class<Void>) Class.getPrimitiveClass("void");
42+
public static final Class<Void> TYPE = Class.getPrimitiveClass("void");
4443

4544
/*
4645
* The Void class cannot be instantiated.

0 commit comments

Comments
 (0)
Please sign in to comment.