0

Is it possible to alter the code of a library imported through Gradle in Android Studio? I am thinking it isn't possible since the libraries get added in at runtime?

Is there anything equivalent of extensions in Swift in Java? An extension in Swift is basically a way to add more functions/methods to an existing class. Without directly altering the original source code.

Thanks in advance!

The Nomad
  • 7,155
  • 14
  • 65
  • 100
  • 1
    "Is it possible to alter the code of a library imported through Gradle in Android Studio?" -- not really. "Is there anything equivalent of extensions in Swift in Java?" -- since few people monitoring the `android` tag are going to be familiar with Swift, you may wish to explain what you mean. – CommonsWare Feb 10 '15 at 00:53
  • 1
    See http://stackoverflow.com/questions/381226/is-it-possible-to-monkey-patch-in-java This seems to be only possible for Java bytecode. For Dex bytecode which is used in Android at runtime, I don't think that approach would work unless someone wrote a tool for that. – Stephan Branczyk Feb 10 '15 at 01:04

1 Answers1

1

Is it possible to alter the code of a library imported through Gradle in Android Studio?

Not as you are defining it, per your Swift extension reference.

An extension in Swift is basically a way to add more functions/methods to an existing class. Without directly altering the original source code.

Java does not have this, sorry.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491