是否存在“无法访问'< init>"的解决方案:它在XYZ中是私有的 [英] Is there a solution to "Cannot access '<init>': it is private in XYZ

查看:219
本文介绍了是否存在“无法访问'< init>"的解决方案:它在XYZ中是私有的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是科特林的新手.我包含了一个我想使用的库,但是在访问它的类时,出现错误消息:无法访问'< init>':它在[类名]中是私有的.我能做些什么吗?在我这方面纠正此错误,还是我只是被扔掉了包裹?

I'm a Kotlin newbie. I included a library I'd like to use, but in accessing on of it's classes I get the error message, "Cannot access '<init>': it is private in [class name]. Is there something I can do to rectify this on my side, or am I just stuck throwing out the package.

推荐答案

该错误表示构造函数是私有的.根据您的评论,我假设您正在使用一个库.在这种情况下,您将必须找到另一种初始化方式.一些库具有类的工厂或构建器,因此请查找任何适用的文档(如果是库或框架).其他人也使用单例模式或其他形式的初始化,在这些情况下,开发人员不要直接使用构造函数.

The error means the constructor is private. Given your comment, I'm assuming you're using a library. If this is the case, you'll have to find a different way to initialize it. Some libraries have factories or builders for classes, so look up any applicable documentation (if it is a library or framework). Others also use the singleton pattern, or other forms of initialization where you, the developer, don't use the constructor directly.

但是,如果这是您的代码,请从构造函数中删除private.如果它是internal,并且您正在尝试在模块外部访问它,请删除internal.请记住,默认可访问性是public .另外,您可以自己使用构建器模式,工厂模式或任何类似的模式.

If, however, it is your code, remove private from the constructor(s). If it's internal and you're trying to access it outside the module, remove internal. Remember, the default accessibility is public. Alternatively, you can use the builder pattern, factory pattern, or anything similar yourself.

这篇关于是否存在“无法访问'&lt; init&gt;"的解决方案:它在XYZ中是私有的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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