0

I'm telling you that I was able to get the highs with and without inheritance automated, but now I have the same problem to edit, it happens I want to first edit the methods of the superclass and then the superclass But I do not succeed:

ParamBuilder.java

private LinkedList<Object>loadMethods(IPersistente ip) throws Exception{
        LinkedList<Method> m = new LinkedList();        
        Child s = ip.getClass().getAnnotation(Child.class);
        Method[] me = null; 
        if(s != null && ip.getId() == 0){
            me = ip.getClass().getSuperclass().getDeclaredMethods();
        } else {
            // only this if is left so that the modifications with inheritances are automated, xq with the highs I could
            if(s != null){
                me = ip.getClass().getSuperclass().getDeclaredMethods();
            } else {
                me = ip.getClass().getDeclaredMethods();
            }     
        }
        for(Method campo : me){            
            if (campo.getName().startsWith("get") && !campo.getName().startsWith("getClass")) {
                Method metodo = campo;
                if(metodo.getParameterCount() == 0) {
                    if(metodo.isAnnotationPresent(Sort.class)){
                        m.add(metodo); 
                    }
                }
            }            
        }
        if(ip instanceof IDependiente && !ip.check()){
            Collections.sort(m, new SortDesc());
        } else {
            Collections.sort(m, new SortAsc());
        }        
        return load(ip, m);
    } 

I await your responses and greetings.

  • 1
    Read the [documentation for getDeclaredMethods()](https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getDeclaredMethods--) and the [documentation for getMethods()](https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getMethods--). One includes inherited methods; the other does not. – VGR Feb 06 '17 at 04:27
  • Ok, But how can I do that if that class has inheritance or is it superclass that uses getmethods and getdeclaredmethods instead? So I have my inheritance: http://pastebin.com/qg72ysGN – detectivejd Feb 06 '17 at 04:47
  • 1
    Just use `getMethods()`. If there is any reason not to use it, try to explain it in understandable sentences. Besides, there is [no reason to use `LinkedList`](http://stackoverflow.com/q/322715/2711488) here (there’s almost never a reason). – Holger Feb 06 '17 at 10:42
  • It is only the condition of the ternary operator, nothing else but that I need to fix, What suggestion do they give me? – detectivejd Feb 15 '17 at 18:48
  • There is no ternary operator here. Unclear what you're now asking, or what you ever were. Comments in Spanish don't help. This site is conducted in English. Also unclear why you aren't now using `getMethods()` as you were told six weeks ago. – user207421 Mar 24 '17 at 00:56
  • Corrected comments, on the other hand I use getMethods () to get the methods of the class but what I try to do is for a class with inheritance, you should first invoke the get of the superclass and then those of the subclass, which does not To edit records and if to save. PS: The ternary operator was removed long ago. – detectivejd Mar 24 '17 at 05:01
  • It remains unclear *why* you're doing all that when there is an existing method that already does it for you. – user207421 Mar 27 '17 at 21:13
  • So what is the method that does what I want to do? I'm telling you, what I'm trying to do is create a hibernate of my own but easier than Have what you need and you can achieve even things that do not jpa, hibernate among others. I looked at the source code of JPA and I could not even imitate its operation to achieve its operation with the database. – detectivejd Mar 28 '17 at 04:48

0 Answers0