Tag Archives: bytecode

How to construct objects in Scala

Scala’s object-oriented programming style comes with some syntactic sugar and a few tricks. In order to get a better understanding of how Scala works, we will examine a few Scala examples and the corresponding byte code (in reality, the Java code resulting from decompiling the class files). Examples Empty class Simplest possible example, an empty… Read More »

Functional programming

This post presents some features of functional programming with Scala. In essence, functional programming is about programming by making use of mathematical functions. All well-known features of functional programming are just a result of using mathematical functions, e.g.: referential transparency immutable state higher-order functions pattern matching I especially like ‘pattern matching’ as it allows for a… Read More »

Inside a class file

In this post, we will explore the inner parts of a class file going byte by byte!!   The class file format is defined at https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html. It says: Each class file contains the definition of a single class or interface. I will add that the class may be public or package-private. For instance, it is possible to… Read More »

Overloading by return type

It is known that one of the limitations of Java is the inability to overload a method by return type as the return type is not part of the signature of the method. According to https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.2, “Two methods or constructors, M and N, have the same signature if they have the same name, the same… Read More »

Generics erasure

The use of Generics allows a type or method to operate on objects of different types while providing compile-time type safety. However, the JVM knows nothing about type parameters or generics as the compiler erases type parameters when creating bytecode. According to https://docs.oracle.com/javase/tutorial/java/generics/erasure.html, type erasure aim is “Type erasure ensures that no new classes are created… Read More »