是否可以在不调用构造函数的情况下在Java中创建对象的实例? [英] Is it possible to create an instance of an object in Java without calling the constructor?

查看:590
本文介绍了是否可以在不调用构造函数的情况下在Java中创建对象的实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修复我的一个程序中的错误,我认为这可能是由于Hibernate确定了如何在不调用其默认(或任何其他)构造函数的情况下实例化对象的实例。

I'm trying to fix a bug in one of my programs which I think might be due to Hibernate figuring out how to instantiate an instance of an object without calling its default (or any other) constructor.

推荐答案

实际上,是的,如果使用 objenesis 为您实例化对象。它实现了字节码操作。

Actually, yes, it is possible to bypass the constructor when you instantiate an object, if you use objenesis to instantiate the object for you. It does bytecode manipulations to achieve this.

反序列化对象也会绕过构造函数。

Deserializing an object will also bypass the constructor.

它不是'可以使用反射来做到这一点。

It isn't possible to do this using reflection.

这篇关于是否可以在不调用构造函数的情况下在Java中创建对象的实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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