Bug 6046 – Not true for Java about Function Hijacking.
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dlang.org
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-05-23T02:45:00Z
Last change time
2015-06-09T05:14:52Z
Assigned to
nobody
Creator
ongbp
Comments
Comment #0 by ongbp — 2011-05-23T02:45:48Z
Hi Digitalmars/Walter Bright,
http://www.digitalmars.com/d/2.0/hijack.html
This talk covers function hijacking, where adding innocent and reasonable declarations in a module can wreak arbitrary havoc on an application program in C++(maybe true) and Java(not true).
Since I have not done C++ for a long while, I am not going to comment about that. But Java I have to place this request for correction from DigitalMars.
javac(from sun) Compiler will complain if there is an ambiguous to link any indentifier that has the same signature for contructor, methods(static/overloaded/overriden)
Overload Sets
Java denys global functions. All functions/methods are within a single class. Within the same class, the overloaded methods cannot have the same signature.
public class MyClass{
public int myVal(){
}
public String myVal(){ // compiler will complain here as error and NOT warning.
}
}
Both the method identifier and zero param list makes a identical signature.
Derived Class Member Function Hijacking
IDE like Netbeans and does flag:
@override
public void myMethodA(){ // Say you did not use the override tag
}
Base Class Member Function Hijacking
to prevent the child class from stealing your implementation for this single method, do:
public final void myMethodA(){ // final == sealed in C#
}
That is shown clearly when you tries to import both this 2 classes within Java:
import java.util.Date;
import java.sql.Date;
public class MyTest{
public static void main(String[] args){
Date now=new Date(); // thinking that you are using java.util.Date;
}
}
Again, as a senior Java Developer since java jdk 1.1 I agrees D as a good replacement for C++ because of modern design and approaches.
Kindly correct that to avoid confusing the new Java to D developer.
There are also other run time intelligent build into JVM to avoid malicious hacker attack on such thing using class proxy & stub.
--
Matthew Ong
email: [email protected]
Comment #1 by schveiguy — 2011-05-23T04:40:59Z
I would say the only valid request here is to mention that Java has the @override flag which can be used to prevent hijacking, but is not the default.
I think you misunderstood the point of this article. The point is to prevent hijacking the *default* must be to prevent hijacking. Having annotations and modifiers that allow you to prevent hijacking is not good enough.
I think you also misunderstood the scope in the article of Java's shortcomings. I think the author only singles out one aspect of Java, it's overload resolution for inherited methods. Nothing else applies to Java.