Java实现 - 元类 [英] Java implementation - Meta classes

查看:77
本文介绍了Java实现 - 元类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解它的方式,Java对象模型是3个级别,每个级别描述它下面的级别,因此所有类共享一个Meta类(它们本身就是对象?)。

The way I understand it, Java object model is 3 levels, each level describes the level beneath it, therefore there is one Meta class shared by all Classes (which are themselves objects?).

我的问题是 - 如何用Java实现构造函数? (或任何其他类方法)我的逻辑说构造函数应该出现在Meta类中,但由于只有一个Meta类,所以它保留所有可能的构造函数没有任何意义,或者我对此的理解是全部错误..

My question is - how are constructors implemented in Java? (or any other class methods) my logic says that constructors should appear in the Meta classes, but since there is only one Meta class, it doesn't make any sense that it keeps all possible constructors, or is my understanding of this is all wrong..

推荐答案

在Java中有一个元类:类的实例用于表示类和接口的类型。构造函数是在类级别定义的,而不是在元类级别定义的。

In Java there's a single metaclass: the instances of the class Class are used to represent the types of classes and interfaces. The constructors are defined at the class level, not at the metaclass level.

这篇关于Java实现 - 元类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆