Java Class类的一些总结

文笔不好这次就不写太多字了,直接贴代码,上半部有注释
package red.sea.daelly.test;

public class Main {

	/**
	 * Class类继承自Object
	 * 
	 * Class类的获取方式:
	 * 1)、Class的静态方法forName  Class.forName(className);
	 * 2)、类的class属性     Test.class;
	 * 3)、类实例的getClass方法    Test test; test.getClass();
	 * 
	 * Class有一个私有的构造函数,我们不能实例化一个Class对象,Class对象的实例化由jvm完成,在jvm加载这个类的时候完成。
	 * 
	 * 可以将Class看做一个普通的“对jvm里加载的类”的抽象的普通类;他有很多的get方法,获取和这个类定义相关的一些信息;
	 * 
	 * Interface的这个抽象也是Class类
	 * 
	 * jvm管理的每个类都是独一无二的Class对象,所以可以用“==”来比较两个类实例如:
	 * 	  if(e.getClass()==Test.class)//这是合法的比较
	 * 一个小技巧:
	 *    Object obj = Class.forName("red.sea.daelly.test.Test").newInstance();//动态通过类型创建一个类的实例对象
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		Class<?> classz = Test.class;
		System.out.println("classz.getCanonicalName():"+classz.getCanonicalName());
		System.out.println("classz.getModifiers():"+classz.getModifiers());
		System.out.println("classz.getName():"+classz.getName());
		System.out.println("classz.getSimpleName():"+classz.getSimpleName());
		System.out.println("classz.getAnnotations():"+classz.getAnnotations());
		System.out.println("classz.getClass():"+classz.getClass());
		System.out.println("classz.getClasses():"+classz.getClasses());
		System.out.println("classz.getClassLoader():"+classz.getClassLoader());
		System.out.println("classz.getComponentType():"+classz.getComponentType());
		System.out.println("classz.getConstructors():"+classz.getConstructors());
		System.out.println("classz.getDeclaredAnnotations():"+classz.getDeclaredAnnotations());
		System.out.println("classz.getDeclaredClasses():"+classz.getDeclaredClasses());
		System.out.println("classz.getDeclaredConstructors():"+classz.getDeclaredConstructors());
		System.out.println("classz.getDeclaredFields():"+classz.getDeclaredFields());
		System.out.println("classz.getDeclaredMethods():"+classz.getDeclaredMethods());
		System.out.println("classz.getDeclaringClass():"+classz.getDeclaringClass());
		System.out.println("classz.getEnclosingClass():"+classz.getEnclosingClass());
		System.out.println("classz.getMethods():"+classz.getMethods());
		System.out.println("classz.getFields():"+classz.getFields());
		System.out.println("classz.getInterfaces():"+classz.getInterfaces());
		System.out.println("classz.getPackage():"+classz.getPackage());
		System.out.println("classz.getSuperclass():"+classz.getSuperclass());
		System.out.println("classz.getGenericInterfaces():"+classz.getGenericInterfaces());
		System.out.println("classz.getGenericSuperclass():"+classz.getGenericSuperclass());
		System.out.println(classz);
	}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java中的复数可以用来进行复数运算和处理。以下是Java中复数总结: 1. Java自带的复数Java中自带了Complex,可以通过导入java.util.Complex包来使用。 2. 复数的定义:复数通常由实部和虚部组成,可以定义一个复数来表示这两个部分。例如: ```java public class Complex { private double real; private double imag; // 构造方法 public Complex(double real, double imag) { this.real = real; this.imag = imag; } // getter和setter方法 public double getReal() { return real; } public void setReal(double real) { this.real = real; } public double getImag() { return imag; } public void setImag(double imag) { this.imag = imag; } } ``` 3. 复数的运算:复数可以进行加、减、乘、除等运算,例如: ```java public Complex add(Complex other) { double real = this.real + other.real; double imag = this.imag + other.imag; return new Complex(real, imag); } public Complex subtract(Complex other) { double real = this.real - other.real; double imag = this.imag - other.imag; return new Complex(real, imag); } public Complex multiply(Complex other) { double real = this.real * other.real - this.imag * other.imag; double imag = this.real * other.imag + this.imag * other.real; return new Complex(real, imag); } public Complex divide(Complex other) { double real = (this.real * other.real + this.imag * other.imag) / (Math.pow(other.real, 2) + Math.pow(other.imag, 2)); double imag = (this.imag * other.real - this.real * other.imag) / (Math.pow(other.real, 2) + Math.pow(other.imag, 2)); return new Complex(real, imag); } ``` 4. 复数的常用方法:复数还可以实现一些常用方法,例如获取模长和相角,例如: ```java public double getModulus() { return Math.sqrt(Math.pow(this.real, 2) + Math.pow(this.imag, 2)); } public double getArgument() { return Math.atan2(this.imag, this.real); } ``` 5. 复数的使用:定义好复数后,就可以通过实例化对象来进行复数运算,例如: ```java Complex c1 = new Complex(2, 3); Complex c2 = new Complex(4, -2); Complex sum = c1.add(c2); Complex difference = c1.subtract(c2); Complex product = c1.multiply(c2); Complex quotient = c1.divide(c2); double modulus = c1.getModulus(); double argument = c1.getArgument(); ``` 以上就是Java复数总结
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值