java field.gettype,Java Field getType()用法及代码示例
java.lang.reflect.Field的getType()方法用于获取此Field对象表示的字段的声明类型。此方法返回一个Class对象,该对象标识声明的类型
用法:
public String getType()
参数:此方法不接受任何内容。
返回值:此方法返回一个Class对象,该对象标识声明的类型。
以下示例程序旨在说明getType()方法:
示例1:
// Java program to demonstrate getType() method
import java.lang.reflect.Field;
public class GFG {
public static void main(String[] args)
throws Exception
{
// Get the marks field object
Field field = User.class.getField("Marks");
// Apply getType Method on User Object
// to get the Type of Marks field
Class value = field.getType();
// print result
System.out.println("Type"
+ " is " + value);
// Now Get the Fees field object
field = User.class.getField("Fees");
// Apply getType Method on User Object
// to get the Type of Fees field
value = field.getType();
// print result
System.out.println("Type"
+ " is " + value);
}
}
// sample User class
class User {
// static double values
public static double Marks = 34.13;
public static float Fees = 3413.99f;
public static double getMarks()
{
return Marks;
}
public static void setMarks(double marks)
{
Marks = marks;
}
public static float getFees()
{
return Fees;
}
public static void setFees(float fees)
{
Fees = fees;
}
}
输出:
Type is double
Type is float
示例2:
// Java program to demonstrate getType() method
import java.lang.reflect.Field;
import java.time.Month;
public class GFG {
public static void main(String[] args)
throws Exception
{
// Get all field objects of Month class
Field[] fields = Month.class.getFields();
for (int i = 0; i < fields.length; i++) {
// print name of Fields
System.out.println("Name of Field: "
+ fields[i].getType());
}
}
}
输出:
Name of Field: class java.time.Month
Name of Field: class java.time.Month
Name of Field: class java.time.Month
Name of Field: class java.time.Month
Name of Field: class java.time.Month
Name of Field: class java.time.Month
Name of Field: class java.time.Month
Name of Field: class java.time.Month
Name of Field: class java.time.Month
Name of Field: class java.time.Month
Name of Field: class java.time.Month
Name of Field: class java.time.Month
java field.gettype,Java Field getType()用法及代码示例相关推荐
- java range对象_Java LocalTime range()用法及代码示例
LocalTime类的range()方法用于获取最小值和最大值形式的字段范围,并将该字段作为参数传递给此方法.此方法的返回值是该字段的ValueRange对象,并且该方法仅对LocalTime对象支持 ...
- java range(10)_Java Year range()用法及代码示例
Year类的range()方法用于获取最大值和最小值的字段范围,并将该字段作为参数传递给此方法.此方法的返回值是该字段的ValueRange对象,并且该方法仅对Year对象支持的那些字段返回Value ...
- java实现stack search_Java Stack search()用法及代码示例
Java中的java.util.Stack.search(Object element)方法用于搜索堆栈中的元素并获取其与顶部的距离.此方法从1开始而不是从0开始计数位置.位于堆栈顶部的元素被视为在位 ...
- java dictionary 实例化_Java Dictionary put()用法及代码示例
字典的put()方法用于在字典中插入映射.这意味着可以将特定键及其值映射到特定字典中. 用法: DICTIONARY.put(key, value) 参数:该方法有两个参数,都属于Dictionary ...
- java中的getfirst_Java LinkedList getFirst()用法及代码示例
Java.util.LinkedList.getFirst()方法用于从LinkedList或列表开头的元素中获取或检索第一个元素. 用法: LinkedList.getFirst() 参数:此方法不 ...
- java byte转bigdecimal_Java BigDecimal byteValueExact()用法及代码示例
java.math.BigDecimal.byteValueExact()是一个内置函数,它将BigDecimal转换为字节并检查丢失的信息.任何大于127或小于-128的BigDecimal值都将生 ...
- java collator_Java Collator compare(String, String)用法及代码示例
java.text.Collator类的compare()方法用于比较两个字符串的强度,并根据结果返回0,正值和负值作为输出. 用法: public abstract int compare(St ...
- java 的 provider_Java Provider.Service getProvider()用法及代码示例
java.security.Provider.Service类的getProvider()方法用于返回此提供程序服务对象的提供程序. 用法: public final Provider getProv ...
- java yearmonth_Java Year atMonth(Month month)用法及代码示例
Java中Year类的atMonth(Month)方法将当前year对象与作为参数传递给月份的month结合起来,以创建YearMonth对象. 用法: public YearMonth atMont ...
- java math.sin()_Java Math sin()用法及代码示例
java.lang.Math.sin()返回介于0.0和pi之间的角度的三角正弦.如果参数为NaN或无穷大,则结果为NaN.如果自变量为零,则结果为零,其符号与自变量相同.返回的值将在-1和1之间. ...
最新文章
- 网络编程--ftp客户端的实现(c#版)
- Octavia 创建 loadbalancer 的实现与分析
- 曼彻斯特解密_曼彻斯特编码解码方法与流程
- Jenkins 程序目录
- linux中fork和exec
- python做数据库管理系统_python+Django+mysql+bootstrap前端,数据库一次搞定)从头教你毕设实现一个简易好看的仓储物资管理之类系统...
- Ubuntu(Debian) 18.04 安装后开启ssh和防火墙传输文件
- 云麦体脂秤华为体脂秤_华为、小米和有品体脂秤哪个品牌好?三款智能体脂秤横评结果排行...
- oracle按照时间点回退,【Oracle】查看事务回滚的时间
- 【Hive】动态分区插入
- Cocos2d-x属性变化动作
- Windows下vim方式操作软件+Gvim使用
- tcl语言读取文件一行_TCL语言笔记:TCL中的列表操作
- AndroidStudio一键国际化方案
- 转福布斯荐75本经商必读
- 三只松鼠商品评论分析
- linux中文麻酱字_红糖麻酱卷的做法——Nice to meet you
- 自媒体新手怎么赚钱,搬运不是长久的出路!
- git clone https 克隆失败解决办法
- 关于unrecognized selector sent to instanc
热门文章
- 免费领取40本前端学习书籍【高清电子版】
- 计算机编程的英语单词大全,计算机编程常用英语单词
- 科技论文写作(写作技巧持续整理)
- 字段缩写ti表示什么_EBSCOhost数据库中,检索字段代码为TI、SO、AU分别表示
- html毕业论文参考文献,本科毕业论文参考文献规范格式
- 风险评估资产重要性识别_基于数据安全的风险评估(一):数据资产识别、脆弱性识别...
- 用matlab编写程序求一组数的均值,用matlab编写一段程序,求加权平均值。
- android图片和文字设计,如何为图片加上精美文字?
- Docker文档资料
- vs2019编译的程序在win7环境上运行失败