JavaTXCompilerInJavaTX/Website/index.html

89 lines
3.6 KiB
HTML
Raw Normal View History

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html> <head>
<title>Java-TX Plugin</title></head>
<center>
<h1>Java-TX Plugin</h1>
</center>
<h2>Content</h2>
<ul>
<li><h4><a href="#introduction">Introduction</a></h4></li>
<li><h4><a href="newJavaTXProject/newJavaTXProject.html" >New Java-TX project</a></h4></li>
<li><h4><a href=" JavaTXExamples.zip" >Example project</a></h4></li>
<li><a href="usePlugin/usePlugin.html" >Using the plugin</a></li>
<li><h4><a href="install/install.html" >Installation</a></h4>
</li>
</ul>
<br/>
<h2 id="introduction">Introduction</h2>
Java-TX (Java Type eXtended) is an extension of Java in which a global type inference algorithm and real function types are added. Since the end of the nineties features from functional program- ming languages have been transferred to Java. Parametric polymorphism extended by wildcards, called generics, were transfered to Java 5.0. Higher-order functions and lambda expression were introduced in Java 8. Java 8 uses functional interfaces as target types of lambda expressions in contrast to real function types as in functional programming languages.
The powerful feature type inference from functional programming languages is incorporated into Java, as into other object-oriented
languages, i.e. only in a restricted way called local type inference. Local type inference allows certain type annotations to be omitted. For instance, it is often not necessary to specify the type of a variable. Type parameters of classes in the new-statement can be left out. Return types of methods can often also be omitted. Local type inference is at its most pronounced in Scala. In Java 10 an extention of local type inference is introduced, where types of local variables can be replaced by the keyword var and inferred automatically during the compilation. In contrast to global type inference, local type inference allows types of recursive methods and lambda expressions not to be omitted.<br>
The Java-TX project contributes to the design of object-oriented languages by developing global type inference algorithms for Java-like languages.
<h3>First Example</h3>
The class <tt>Id</tt> has the method <tt>id</tt>. The type annotations are omitted.
<br/>
<pre> <code class="language-java">
class Id {
id(x) {
return x;
}
}
</code> </pre>
The type inference algorithm inferrs the types, such that <tt>Id</tt> can be applied:
<pre>
new Id().id(1);
new Id().id("hallo");
</pre>
<h3>More complex example</h3>
<pre>
import java.lang.Integer;
import java.lang.Double;
import java.lang.String;
class OL {
m(x) { return x + x; }
}
class OLMain {
main(x) {
var ol;
ol = new OL();
return ol.m(x);
}
}
</pre>
The type inference mechanism considers only imported types. Therefore <tt>Integer</tt> <tt>Double</tt>, and <tt>String</tt> are imported.
<br/>
As the operator <tt>+</tt> is overloaded by all numeric types and String the methods <tt>m</tt> in the class <tt>OL</tt> and <tt>main</tt> in the class <tt>OLMain</tt>, respectively, gets all these types. The generated classfile demonstrates this:
<pre>
> javap OL.class
Compiled from "OL.jav"
class OL {
public OL();
public java.lang.Integer m(java.lang.Integer);
public java.lang.Double m(java.lang.Double);
}
> javap OLMain.class
Compiled from "OLMain.jav"
class OLMain {
public OLMain();
public java.lang.Integer main(java.lang.Integer);
public java.lang.Double main(java.lang.Double);
}
</pre>
<hr>
<address></address>
<!-- hhmts start -->Last modified: Fri Jun 1 16:43:55 CEST 2018 <!-- hhmts end -->
</body> </html>