{"action":"created","issue":{"url":"https://api.github.com/repos/golo-lang/golo-lang/issues/271","labels_url":"https://api.github.com/repos/golo-lang/golo-lang/issues/271/labels{/name}","comments_url":"https://api.github.com/repos/golo-lang/golo-lang/issues/271/comments","events_url":"https://api.github.com/repos/golo-lang/golo-lang/issues/271/events","html_url":"https://github.com/golo-lang/golo-lang/issues/271","id":81878490,"number":271,"title":"So I tried to override a ClassLoader, and then ...","user":{"login":"Artpej","id":693299,"avatar_url":"https://avatars.githubusercontent.com/u/693299?v=3","gravatar_id":"","url":"https://api.github.com/users/Artpej","html_url":"https://github.com/Artpej","followers_url":"https://api.github.com/users/Artpej/followers","following_url":"https://api.github.com/users/Artpej/following{/other_user}","gists_url":"https://api.github.com/users/Artpej/gists{/gist_id}","starred_url":"https://api.github.com/users/Artpej/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Artpej/subscriptions","organizations_url":"https://api.github.com/users/Artpej/orgs","repos_url":"https://api.github.com/users/Artpej/repos","events_url":"https://api.github.com/users/Artpej/events{/privacy}","received_events_url":"https://api.github.com/users/Artpej/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/golo-lang/golo-lang/labels/improvement","name":"improvement","color":"02d7e1"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-05-28T11:02:13Z","updated_at":"2015-05-28T11:26:54Z","closed_at":null,"body":"When I tried to override a ClassLoader with the `AdapterFabric` or `Adapters` some issues append.\r\n\r\n(reminder) This is a part of the `ClassLoader` prototype:\r\n```java\r\npublic abstract class ClassLoader {\r\n\r\n  //...\r\n\r\n  public Class<?> loadClass(String name) throws ClassNotFoundException {\r\n    //...\r\n  }\r\n\r\n  protected Class<?> loadClass(String name, boolean resolve) \r\n      throws ClassNotFoundException{\r\n    //...\r\n  }\r\n\r\n  protected final Class<?> defineClass(String name, byte[] b, int off, int len)\r\n        throws ClassFormatError {\r\n    //...\r\n  }\r\n\r\n  protected final Class<?> findLoadedClass(String name) {\r\n    //...\r\n  }\r\n\r\n  //...\r\n\r\n}\r\n```\r\n\r\nLet's see what's append with the following code:\r\n\r\n```golo\r\nlocal function create = {\r\n  return Adapter():\r\n     extends(\"java.lang.ClassLoader\"):\r\n     overrides(\"loadClass\", |super, this, name, resolve| {\r\n        let already_loaded = this: findLoadedClass(name)\r\n       # ...\r\n        let defined = this: defineClass(...)        \r\n       # ...\r\n     }): newInstance()\r\n    \r\n}\r\n```\r\n\r\nThe `ClassLoader` class contains two methods named `loadClass`. Overriding one of them cause the second one is no more visible because of the method resolution in the `Adapter`:\r\n```golo\r\ncreate(): loadClass(\"java.lang.Object\")\r\n```\r\nIn this case `Class<?> loadClass(String name)` is not resolved. This appends because the resolver find a method named `loadClass` in the overrided methods `set` and return it directly, but it's the wrong one.\r\n\r\nThe overrided methods are stored in a `map` with the method's name as `key`. So it is not possible to override two methods with the same name and with a different arity.\r\n\r\nAnother issue append when I invoke ` this: findLoadedClass(...)`  or `this: defineClass(...)`. Both are not found in this context. It is because both methods are protected and not overrided, and according the documentation of [getDeclaredMethods](https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getDeclaredMethods()) and [getMethods](https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getMethods()) there's no direct way to obtain the inherited protected method of a class."},"comment":{"url":"https://api.github.com/repos/golo-lang/golo-lang/issues/comments/106284118","html_url":"https://github.com/golo-lang/golo-lang/issues/271#issuecomment-106284118","issue_url":"https://api.github.com/repos/golo-lang/golo-lang/issues/271","id":106284118,"user":{"login":"Artpej","id":693299,"avatar_url":"https://avatars.githubusercontent.com/u/693299?v=3","gravatar_id":"","url":"https://api.github.com/users/Artpej","html_url":"https://github.com/Artpej","followers_url":"https://api.github.com/users/Artpej/followers","following_url":"https://api.github.com/users/Artpej/following{/other_user}","gists_url":"https://api.github.com/users/Artpej/gists{/gist_id}","starred_url":"https://api.github.com/users/Artpej/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Artpej/subscriptions","organizations_url":"https://api.github.com/users/Artpej/orgs","repos_url":"https://api.github.com/users/Artpej/repos","events_url":"https://api.github.com/users/Artpej/events{/privacy}","received_events_url":"https://api.github.com/users/Artpej/received_events","type":"User","site_admin":false},"created_at":"2015-05-28T11:26:53Z","updated_at":"2015-05-28T11:26:53Z","body":"`super` is a function reference not an object (it's the parent's overrided method) :wink: "}}