author | avstepan |
Thu, 24 Sep 2015 17:07:44 +0300 | |
changeset 32769 | c9520bbd6754 |
parent 28056 | 0cab6eb92852 |
child 39731 | 7a4bc90065bd |
permissions | -rw-r--r-- |
2 | 1 |
/* |
17456
0f2c187cd188
8014357: Minor refactorings to sun.reflect.generics.reflectiveObjects.*
darcy
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.reflect.generics.reflectiveObjects; |
|
27 |
||
28 |
import java.lang.reflect.GenericArrayType; |
|
29 |
import java.lang.reflect.Type; |
|
17456
0f2c187cd188
8014357: Minor refactorings to sun.reflect.generics.reflectiveObjects.*
darcy
parents:
5506
diff
changeset
|
30 |
import java.util.Objects; |
2 | 31 |
|
32 |
/** |
|
33 |
* Implementation of GenericArrayType interface for core reflection. |
|
34 |
*/ |
|
35 |
public class GenericArrayTypeImpl |
|
36 |
implements GenericArrayType { |
|
27489
cf53b2c02ebb
8062771: Core reflection should use final fields whenever possible
martin
parents:
25859
diff
changeset
|
37 |
private final Type genericComponentType; |
2 | 38 |
|
39 |
// private constructor enforces use of static factory |
|
40 |
private GenericArrayTypeImpl(Type ct) { |
|
41 |
genericComponentType = ct; |
|
42 |
} |
|
43 |
||
44 |
/** |
|
45 |
* Factory method. |
|
46 |
* @param ct - the desired component type of the generic array type |
|
47 |
* being created |
|
48 |
* @return a generic array type with the desired component type |
|
49 |
*/ |
|
50 |
public static GenericArrayTypeImpl make(Type ct) { |
|
51 |
return new GenericArrayTypeImpl(ct); |
|
52 |
} |
|
53 |
||
54 |
||
55 |
/** |
|
32769
c9520bbd6754
8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents:
28056
diff
changeset
|
56 |
* Returns a {@code Type} object representing the component type |
2 | 57 |
* of this array. |
58 |
* |
|
32769
c9520bbd6754
8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents:
28056
diff
changeset
|
59 |
* @return a {@code Type} object representing the component type |
2 | 60 |
* of this array |
61 |
* @since 1.5 |
|
62 |
*/ |
|
63 |
public Type getGenericComponentType() { |
|
64 |
return genericComponentType; // return cached component type |
|
65 |
} |
|
66 |
||
67 |
public String toString() { |
|
68 |
Type componentType = getGenericComponentType(); |
|
69 |
StringBuilder sb = new StringBuilder(); |
|
70 |
||
71 |
if (componentType instanceof Class) |
|
72 |
sb.append(((Class)componentType).getName() ); |
|
73 |
else |
|
74 |
sb.append(componentType.toString()); |
|
75 |
sb.append("[]"); |
|
76 |
return sb.toString(); |
|
77 |
} |
|
78 |
||
79 |
@Override |
|
80 |
public boolean equals(Object o) { |
|
81 |
if (o instanceof GenericArrayType) { |
|
82 |
GenericArrayType that = (GenericArrayType) o; |
|
83 |
||
17456
0f2c187cd188
8014357: Minor refactorings to sun.reflect.generics.reflectiveObjects.*
darcy
parents:
5506
diff
changeset
|
84 |
return Objects.equals(genericComponentType, that.getGenericComponentType()); |
2 | 85 |
} else |
86 |
return false; |
|
87 |
} |
|
88 |
||
89 |
@Override |
|
90 |
public int hashCode() { |
|
17456
0f2c187cd188
8014357: Minor refactorings to sun.reflect.generics.reflectiveObjects.*
darcy
parents:
5506
diff
changeset
|
91 |
return Objects.hashCode(genericComponentType); |
2 | 92 |
} |
93 |
} |