Programming language: Kotlin
License: Apache License 2.0
Tags: Misc    

Strukt alternatives and similar libraries

Based on the "Misc" category.
Alternatively, view Strukt alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of Strukt or a related project?

Add another 'Misc' Library



C-style structs on the JVM!

ZERO garbage, ZERO reflection, ZERO maps. EASY to use, and with INCREDIBLE performance.

Build Status license

WARNING: This library is more of a proof-of-concept, and is extremely experimental and untested. DO NOT USE IN PRODUCTION!

New! Now fully supported across all JVM languages!


compile group: 'org.jire.strukt', name: 'strukt', version: '1.2.0'



Declaring a Strukt

The declaration syntax is very similar to regular classes, except:

  • You should declare as an object, rather than class
  • Members should be delegated by a subclass of StruktMember
  • You must extend Strukt

For example, a Strukt for representing a coordinate might look like:

object Point : Strukt() {
    var x by 0
    var y by 0

There are member delegates built in for all primitives besides char.

You can also specify a default value for your member, like so:

var x by 3 // 3 is the default value
var y by 5 // 5 is the default value, shown with named arguments

Allocating a reference

The syntax for allocation is a bit different than regular object construction. Instead, you use the invoke operator to set values.

For the above Point example, this might look like:

val example = Point { x = 3; y = 5 }

If you wanted to make use of default arguments, you can omit the sets.

val example = Point {}

Allocating a reference automatically sets the reference pointer. (More on this in the following section.)

Accessing members

Accessing members is the farthest deviation from regular object syntax.

It is important to understand under the hood, Strukt uses something called a reference pointer to keep track of what reference is currently being worked on.

Switching to a reference pointer is done through the get operator on the Strukt's type.

This might look like this:


In full effect, the Point example might be used like this:

Point[example].y = 20
println("x: ${Point[example].x}, y: ${Point[example].y}") // prints "x: 3, y: 20"

Since the switch (get) operator switches the reference pointer, you can write a shorthand version by referring to the type (Point in our example) directly.

This might look like:

Point[example].x = 123 // `Point[example]` sets the reference pointer...
println("x: ${Point.x}, y: ${Point.y}") // so `Point.x` and `Point.y` can be referred to directly

*Note that all licence references and agreements mentioned in the Strukt README section above are relevant to that project's source code only.