class A { void F() { System.out.println("a"); }} class B extends A { void F() { System.out.println("b"); }} public class X { public static void main(String[] args) { A objA = new B(); objA.F(); } }
Here F()is called dynamic, is not it?
F()
This article says:
... Java bytecode does not support dynamic method invocation. There are three supported calling modes: invokestatic, invokespecial, invokeinterface, or invokevirtual. These modes allow calling methods with a well-known signature. We are talking about a strongly typed language. This allows you to do some checks directly at compile time.Dynamic languages, on the other hand, use dynamic types. So we can call a method that is unknown when compiling time, but this is completely impossible with Java bytecode.
... Java bytecode does not support dynamic method invocation. There are three supported calling modes: invokestatic, invokespecial, invokeinterface, or invokevirtual. These modes allow calling methods with a well-known signature. We are talking about a strongly typed language. This allows you to do some checks directly at compile time.
Dynamic languages, on the other hand, use dynamic types. So we can call a method that is unknown when compiling time, but this is completely impossible with Java bytecode.
What am I missing?
.
, , , , .
?
, Java B, objA B; , , B A, (objA F).
B
objA
A
F
, , F, , , , .
: invokedynamic โโ Java7, JVM, script JVM, . , ( Grovvy MetaClass), Sun .
invokedynamic
MetaClass
, B A. ; .. B; . - - (, ).
, - .
, "invokevirtual", .
"", . ( ). , , - , .
"" (. Method). , , , ( , ).
. , , , / , Java .
You can create functional interfaces.
class Logger { private BiConsumer<Object, Integer> logger = null; // ... private Logger(Object logger) { this.akkaLogger = (LoggingAdapter) logger; this.logger = (message, level) -> { switch (level) { case INFO: akkaInfo(message); break; case DEBUG: akkaDebug(message); break; case ERROR: akkaError(message); break; case WARN: akkaWarn(message); break; } }; } private Logger() { this.logger = (message, level) -> System.out.println(message); } // ... }
Source: https://habr.com/ru/post/1740485/More articles:How to center an html table? - htmlSaving images for each user on a website (php) - databaseHow to avoid boxing / unpacking when expanding System.Object? - c #Joining a comment () to add a surrounding tag - commentsHow to encode special characters for POST using Spring / Roo - javaHow to get the logical results of a regular expression in Ant? - regexHow to get a complete project by date in Source Safe? - visual-sourcesafeWhat is the difference between [A, B] and [A; B] in MatLab? - syntaxThe Ado.net Fill method does not throw an error when starting a stored procedure that does not exist - c #ะะพัััะฟ ะบ InfoMessages ะดะปั ะทะฐะฟัะพัะพะฒ SQL Server ะฒ ะก# - c#All Articles