Solved Reflection help! urgent!

Discussion in 'Plugin Development' started by mine-care, Feb 11, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    mine-care

    Hello bukkit members! i am in a kind of dead end... i am trying to override a method that returns MerchantRecipeList in a class i want to be Version independed.
    the problem is, how can i make it return Object (since i dont want to import MerchantRecipeList, because its in a version depended package)
    Here is the method:
    Code:
                @Override
                public MerchantRecipeList getOffers(EntityHuman arg0) {
                    return ObjectThatIsMerchantRecipeList;
                }
    //How do i define this method? it wont accept Object as return type since it is been overwritten method D:
    
    Thanks a lot.
     
  2. Offline

    TehHypnoz

    As far as I know you can't override methods with reflection, only invoke them. Sorry if I'm wrong.
     
  3. Offline

    Funergy

  4. Offline

    mine-care

    @Funergy Thanks, will look on that when i get home :3

    @TehHypnoz thats what i am thinking too...
     
  5. Offline

    mythbusterma

    @mine-care

    He's right. The JVM, as per standard, only supports "reflection," i.e. using code to examine code. The operation you're trying to perform is runtime modification of code, which is not reflection, rather it is "introspection," which Java does not have support for.

    That being said, you can use a modified classloader module from ASM to add this functionality. Even then, it's extremely dangerous.

    Simply make it return Object, that's your best bet.
     
    mine-care likes this.
  6. Offline

    mine-care

    @mythbusterma
    Thanks for that clarification of runtime, it makes sense and clears the foggy atmosphere... Well I can't make it return object though because it's an overwritten method from IMechant class :- (
    I understand the risks of a modes classloader and I don't want to mess with it..
    Thanks a lot for your reply, it was vital
     
Thread Status:
Not open for further replies.

Share This Page