1 /* 2 * Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved. 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 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 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 * 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. 24 */ 25 26 package com.sun.jdi; 27 28 /** 29 * A class or instance variable in the target VM. 30 * See {@link TypeComponent} 31 * for general information about Field and Method mirrors. 32 * 33 * @see ObjectReference 34 * @see ReferenceType 35 * 36 * @author Robert Field 37 * @author Gordon Hirsch 38 * @author James McIlree 39 * @since 1.3 40 */ 41 public interface Field extends TypeComponent, Comparable<Field> { 42 43 /** 44 * Returns a text representation of the type 45 * of this field. 46 * Where the type is the type specified in the declaration 47 * of this field. 48 * <P> 49 * This type name is always available even if 50 * the type has not yet been created or loaded. 51 * 52 * @return a String representing the 53 * type of this field. 54 */ 55 String typeName(); 56 57 /** 58 * Returns the type of this field. 59 * Where the type is the type specified in the declaration 60 * of this field. 61 * <P> 62 * For example, if a target class defines: 63 * <PRE> 64 * short s; 65 * Date d; 66 * byte[] ba;</PRE> 67 * And the JDI client defines these <CODE>Field</CODE> objects: 68 * <PRE> 69 * Field sField = targetClass.fieldByName("s"); 70 * Field dField = targetClass.fieldByName("d"); 71 * Field baField = targetClass.fieldByName("ba");</PRE> 72 * to mirror the corresponding fields, then <CODE>sField.type()</CODE> 73 * is a {@link ShortType}, <CODE>dField.type()</CODE> is the 74 * {@link ReferenceType} for <CODE>java.util.Date</CODE> and 75 * <CODE>((ArrayType)(baField.type())).componentType()</CODE> is a 76 * {@link ByteType}. 77 * <P> 78 * Note: if the type of this field is a reference type (class, 79 * interface, or array) and it has not been created or loaded 80 * by the declaring type's class loader - that is, 81 * {@link TypeComponent#declaringType <CODE>declaringType()</CODE>} 82 * <CODE>.classLoader()</CODE>, 83 * then ClassNotLoadedException will be thrown. 84 * Also, a reference type may have been loaded but not yet prepared, 85 * in which case the type will be returned 86 * but attempts to perform some operations on the returned type 87 * (e.g. {@link ReferenceType#fields() fields()}) will throw 88 * a {@link ClassNotPreparedException}. 89 * Use {@link ReferenceType#isPrepared()} to determine if 90 * a reference type is prepared. 91 * 92 * @see Type 93 * @return the {@link Type} of this field. 94 * @throws ClassNotLoadedException if the type has not yet been loaded 95 * or created through the appropriate class loader. 96 */ 97 Type type() throws ClassNotLoadedException; 98 99 /** 100 * Determine if this is a transient field. 101 * 102 * @return <code>true</code> if this field is transient; false otherwise. 103 */ 104 boolean isTransient(); 105 106 /** 107 * Determine if this is a volatile field. 108 * 109 * @return <code>true</code> if this field is volatile; false otherwise. 110 */ 111 boolean isVolatile(); 112 113 /** 114 * Determine if this is a field that represents an enum constant. 115 * @return <code>true</code> if this field represents an enum constant; 116 * false otherwise. 117 */ 118 boolean isEnumConstant(); 119 120 /** 121 * Compares the specified Object with this field for equality. 122 * 123 * @return true if the Object is a Field and if both 124 * mirror the same field (declared in the same class or interface, in 125 * the same VM). 126 */ 127 boolean equals(Object obj); 128 129 /** 130 * Returns the hash code value for this Field. 131 * 132 * @return the integer hash code 133 */ 134 int hashCode(); 135 }