Hibernate
@Entity
@OptimisticLocking(type = VERSION)
@Table(name = "HIB_PERSON")
@Proxy(lazy = false)
@Access(javax.persistence.AccessType.FIELD)
@BatchSize(size = 10)
@Cache(usage = READ_WRITE)
public class Person extends AuditablePersistent implements PersonIdentifier {
@OneToOne(optional = true)
@NotFound(action = NotFoundAction.EXCEPTION)
@PrimaryKeyJoinColumn
private Employee employee;
@ManyToOne(optional = true)
@JoinColumn(name = "org_id")
@NotFound(action = NotFoundAction.EXCEPTION)
@Fetch(FetchMode.JOIN)
private Organisation organisation;
@Column(nullable = false, columnDefinition = "boolean default false")
private boolean registrationPending;
...
Java Server Face
<html>
<head><title>Hallo Leute</title></head>
<body>
<%
double num = Math.random();
if (num > 0.95) {
%>
<h2>Freut euch auf einen verdammt guten Vortrag!</h2><p>(<%= num %>)</p>
<%
} else {
%>
<h2>Freut euch auf ein gutes Gespräch mit eurem Sitznachbarn</h2><p>(<%= num %>)</p>
<%
}
%>
<a href="<%= request.getRequestURI() %>"><h3>Nochmal drüber nachdenken?</h3></a>
</body>
</html>
React
import { Component } from '@someframework/core';
@Component ({
selector: 'my-app',
template: '<h1>Hallo {{name}}</h1>';
})
export class AppComponent { name = 'Leute'; }
Vaadin
@Title("My UI")
public class HelloWorld extends UI {
@Override
protected void init(Request request) {
VerticalLayout content = new VerticalLayout();
setContent(content);
content.addComponent(new Label("Hello Leute!"));
content.addComponent(new Button("Drück mich!",
click -> Notification.show("Heute hab ich eine Sache gelernt!")));
}
}
Ktor
fun Application.module() {
routing { get("/") {
call.respondHtml {
head {
link(rel = "stylesheet", href = "/styles.css", type = "text/css")
}
body {
styleCss {
rule("p.demo") {
color = Color.green
}
}
p {
+"Hello"
span {
style {
textDecoration(TextDecorationLine.underline)
}
+" Folks!"
}
}
}
}
}
}
}
"Entwickler, die Software entwerfen,
sind gezwungen diese mit Lösungen zu implementieren, welche die Sprache, Libs, Frameworks und Tools abbilden."
Tobse F
... und wie man sie einsetzt
Prägnant
public class Person {
private final String firstName;
private final String lastName;
private final LocalDate birthDay;
public Person(String firstName, String lastName,
LocalDate birthDay) {
this.firstName = firstName;
this.lastName = lastName;
this.birthDay = birthDay;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public LocalDate getBirthDay() {
return birthDay;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Person person = (Person) o;
return Objects.equals(firstName, person.firstName) &&
Objects.equals(lastName, person.lastName) &&
Objects.equals(birthDay, person.birthDay);
}
@Override
public int hashCode() {
return Objects.hash(firstName, lastName, birthDay);
}
@Override
public String toString() {
return "Person{" +
"firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", birthDay=" + birthDay +
'}';
}
}
data class PersonK(
val firstName: String,
val lastName: String,
val birthDay: LocalDate
)
Java
Kotlin
Sicher
var output: String
output = null
Kotlin
val name: String? = null
println(name.length)
fun calculateTotal(obj: Any) {
if (obj is Invoice){
obj.calculateTotal()
}
}
fun isCloneBaby(father: Person, son: Person): Boolean {
return father == son
}
// compile Error
// compile Error
// Autocast
// equals()
Interoperabel
Interoperabel
fun callJava(){
val backend = LegacyBackend()
backend.sendMail("Be prepared... we deploy")
}
Kotlin
private void callKotlin(){
var backend = new NewBackend();
backend.sendSlack("We introduced NetID oAuth!");
}
Java
Optimales Tooling
💎
UPDATE
inline class CM(val number: Double = 1.0){
fun toInch() = number * 2.54
fun toFeet() = number * 0.0328084
override fun toString(): String {
return "$number cm"
}
}
fun main() {
println(CM(1.0))
println(CM(1.0).toFeet())
println(CM(1.0).toInch())
cutTheRope(length = CM(20.0))
}
var ropeLength = CM(100.0)
fun cutTheRope(length:CM ){
ropeLength = CM(ropeLength.number + length.number)
println("Remaining rope: $length")
}
fun weeNeedBoxedValue(value: CM?){
value?.apply (::println)
}
public static final void cutTheRope(double length) {
ropeLength = CM.constructor-impl(ropeLength + length);
String var2 = "Remaining rope: " + CM.toString-impl(length);
System.out.println(var2);
}
public static final void weeNeedBoxedValue(@Nullable CM value) {
if (value != null) {
System.out.println(value);
}
}
typealias cm = Double
fun main() {
cutTheRope( 20.0)
}
var ropeLength : cm = 100.0
fun cutTheRope(length: cm){
ropeLength -= length
println("New rope length: $ropeLength cm")
}
typealias ExceptionMap = Map<Int, ()->DatatypeConfigurationException>
fun configure(mappings: ExceptionMap){
mappings[0]?.invoke()
}
fun main() {
val theAnswer = 42u
pronounce(theAnswer)
pronounce(42.toUInt())
pronounce(42) // ⚡ Compile error
}
fun pronounce(answer: UInt){
print("The answer is $answer")
}
Coroutinen sind leichtgewichtige Threads.
Sie können angehalten werden,
ohne den Thread zu blockieren.
Suspending
Launch startet eine Coroutine und
gibt einen Job zurück.
Async ist wie Launch, nur mit Rückgabewert.
Await wartet auf den Rückgabewert.
Async / Await
Launch
open class Animal(var isAlive: Boolean)
class Unicorn : Animal(true){
fun doMagicPoop() = print("🌈✨")
}
fun Animal.isMagical() : Boolean{
contract {
returns(true) implies (this@isMagical is Unicorn)
}
return this is Unicorn && isAlive
}
fun main() {
val babyUnicorn : Animal = Unicorn()
if (babyUnicorn.isMagical()) {
babyUnicorn.doMagicPoop()
}
}
plugins {
kotlin("jvm") version "1.3.30"
java
}
group = "de.tfr.presentation"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib-js"))
testCompile("junit", "junit", "4.12")
}
configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_1_8
}
fun ourCoolBuildScript(){
val timeStamp = LocalDateTime.now()
downloadI18nMessages()
formatMessageProperties()
mergeChangeLogEntries(timeStamp)
sendSlackMessage("We gonna deploy that stuff 🤘")
}
*.kts