简体   繁体   English

Java类过滤器可在自定义加载程序中引用类时加载不同版本的同一类?

[英]Java class filter to load same class of different versions when class referred in custom loader?

To illustrate the scenario, I have a class called com.test.A and the same class would be modified by different users (eg: DEV1 & DEV2) but they modify their respective classes, eg: com.test.DEV1.A , com.test.DEV2.A 为了说明这种情况,我有一个名为com.test.A的类,同一类将由不同的用户修改(例如:DEV1和DEV2),但是他们修改了各自的类,例如:com.test.DEV1.A,com .test.DEV2.A

If I use custom loader and load class A, is there any possibility that i can filter the reference of A to DEV1.A or DEV2.A based on some condition? 如果我使用自定义加载程序并加载类A,是否有可能根据某种条件过滤A对DEV1.A或DEV2.A的引用?

Without further knowledge of the problem I would say you are trying to solve this problem in the wrong place. 如果没有对该问题的进一步了解,我会说您正在尝试在错误的位置解决此问题。

This looks more like a branching problem, that should be solved in the configuration management level, using the features that your SCM gives you. 这看起来更像是分支问题,应使用SCM为您提供的功能在配置管理级别中解决。 Please have a look at this article on how to handle properly different parallel developments https://thedailywtf.com/articles/Source-Control-Done-Right 请看一下这篇文章,了解如何正确处理不同的并行开发https://thedailywtf.com/articles/Source-Control-Done-Right

The tone is quite accessible and I have used it with success in order to introduce branching to teams, I hope you enjoy it 语气很容易理解,为了将分支引入团队,我已经成功地使用了它,希望您喜欢

Class A {
    methodForUser1(params);
    methodForUser2(params);
    ....
    wrapperMethod(params) {
        if (context.user.equals(user1)) 
            methodForUser1(params);
        else if (context.user.equals(user2))
            methodForUser2(params)
        ....
    }
}

Now every user only have to call wrapperMethod and it will in turn delegate to the right method you have for the user in context. 现在,每个用户只需调用wrapperMethod,它将依次委托给您在上下文中为该用户使用的正确方法。

This is brute way of doing it. 这是蛮横的方式。 Additionally, you can load the method using reflection. 此外,您可以使用反射来加载方法。

Another approach could be what @Jorge_B is suggesting in another answer (maintaining different CI pipelines) 另一种方法可能是@Jorge_B在另一个答案中建议的内容(保持不同的CI管道)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM