Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我使用工厂方法来实例化对象,那么是否可以引用正在实例化的对象的类属性的文档块描述?
我发现自己正在查看类以提醒我为工厂方法提供哪些参数。如果我可以从工厂输出的所有对象中引用所有相关的文档块描述,那会很方便,然后我的 IDE 会在我调用工厂方法时提示我。
对于您描述的场景,我能看到的最佳路径是让所有这些潜在的类实现相同的接口,或者可能从相同的抽象父类扩展。然后,在工厂方法上使用 @return 表示它返回该接口/抽象的对象。这样,IDE 将能够从接口/抽象的代码中读取文档块并向您呈现信息。