Tumgik
#tostring()
javatpoint · 3 months
Text
Understanding the Java toString() Method: Advantages and Disadvantages
Understanding the Java toString() Method In Java, the toString() method is an essential part of the Object class, the superclass of all Java classes. This method returns a string representation of the object, which can be useful for debugging, logging, and displaying object information in a human-readable format. In this blog post, we will explore the advantages and disadvantages of the…
View On WordPress
0 notes
benslittlestarkiller · 7 months
Text
CoD Headcanons: How they Act when You don't Look both Way when crossing Street and Vehicle is Coming at You
I was inspired by something that happen to me today when I go to store
Phillip Grapes
Tumblr media
Phillip was in his Lifted truck driving 80 MPH down the road when you were crossing Street holing Grocerie. Including Eggs and Avocado. For tonights toast dinner. You looked up at sund of cunty music blasting and saw the red white and blue vehicle flying toward you, you droped paper bag, eggs and toast crawshing to floor. Suddenly LOUD SCREECH!!! fill ears. as Philly come to a stop. HE ohped out of the truck, his truck ballz swinging as he slamed it shut. He stomp over to you about to yell whemn…… he see your beauty, his eye go es wide. H is speehless. snd loo at u. with LIST (see Gif above) He stoppe down and pick up egg adn avicadphillip jro anf tostred. “Hey babe, wanna come to me bbq 2nite?” Hr say? ]’the wife kkifds, sclottish hubnk and David plus the kids (clownius, Amberleigh Lynn, and Phillp jr will all be there.” You. aceept. “Ok.” and both of you go into lifty virile and masculine Dodge Ram F150 Tundra Truvk with 40 inch double wheels and over head lights on truck. (Phillip love he truck named “Liberty”} sp yuo jolined the Grapes cklan at the beach where BBQ was. held around bone fire. And 9 molnths latwser you pregnant with Philipa baby grl Grapes. The family invvciged you tol live in theuir mansion with them, 5 stories wiht lots of land. You join afamily (y/n) Grapes. Phillip dad show you his coin collection.
PART 2 Comign soon.
23 notes · View notes
lunarsilkscreen · 7 months
Text
A New Programming Numeric - White Paper
Thanks to the 1/3 problem; we know that floating point numbers aren't exactly accurate. What can we do about it?
I propose a new kind of numeric that retains its divisor (or any other radicals) until such a time it becomes an integer again. When used as a string for display or other visual output purposes; it would then give its approximate representation. And if using an appropriate display-encoding system; any and all required notation.
It would look like what we already have now, int, float, or string; but the operators would be assigned differently.
Numeric {
Numeric num=1, div=1; string rep;
+(numeric oth){
let x = oth.num;
if (div!=oth.div) x*=div and (num*=oth.div && div*=oth.div)
num+=x;
}; -{};*{};/{};%{}; //...etc
toString(){return rep||(rep=num/div)}
Update() { /*meat and potatoes everytime the number is updated, check if the num/div can be simplified by reducing the div to as close to 1 as possible.*/}
}
There are obvious performance issues that are immediately apparent in this incomplete pseudo-code. However, I believe that there's a lot of usage we can get from this in the sectors that require much more precision than modern languages and scripting currently give on the surface.
Essentially; a lot of the separated (Math) libraries would be brought under one roof, and that could theoretically improve accuracy.
10 notes · View notes
leftsquarebracket · 7 months
Note
it feels wrong that it is the first letter of the second 'object' that's capitalized rather than the first
you can blame JavaScript for this and many other bizarre decisions - that's the default string representation for objects. there's also [object Array], [object Type], etc.
6 notes · View notes
milesfagworth · 5 months
Note
Hi milord fagworth! I was curious about your top five functions/methods in a programming language of your choice!
Or, if answering questions about programming is cringe, I'd like to know your top five pokemon! If you don't like pokemon i will also accept Digimon but I won't recognize them
You get two of three! i do not know digimon
top five functions in Java:
1. system.out.println(). love to Know Things, the original debugger
2. toString(). tell me about that object! what are the values! also useful for debugging
3. Any no arg constructor. Your values are NULL until I decide to set them later. gimme an object with nuthin
4. sort(). automated autism, put those elements in some kind of order!
5. getMessage() IF the exception handling is good. Tell me what went wrong queen
Pokemon time!
1. Schroodle! he is just a lil guy and i love him
2. Skeledirge! big fiery gator and they sing??? impeccable
3. magikarp! i have such a soft spot for those fish, i want only good things for them
4. cacnea! another lil guy, hes a cactus!
5. woobat! literal heart eye, what else is there to say?
thank you so much for asking!! this was a ton of fun :)
2 notes · View notes
log6 · 11 months
Note
nvm i found it, it's the 0 == "0" and 0 == [] then surely "0" == [] one
this makes sense because of types but that's also why it doesn't make sense. The type coercion of the loose comparator (==) is one of the most useful features in the language but only if you understand it because it causes endless problems if you don't. for any x == y, with an x of TypeA and a y of TypeB, JS does this. is the boolean value of x equivalent to the boolean value of y when forced to TypeA? in this case, 0, a FALSE boolean value, is compared to Number("0") which is just 0, yielding TRUE Number([]) yields 0, giving us 0 == 0 and another TRUE however, Array.from("0") provides ['0'], which, as an array with something in it, is TRUE, and therefore not equivalent to an empty array. This also works backwards. [].toString() yields "" (the empty string) a FALSE value, not equivalent to "0", a nonempty string.
3 notes · View notes
net-craft · 1 year
Text
12 Top Kotlin Features to Enhance Android App Development Process
Tumblr media
Kotlin is a modern and concise programming language that is designed to run on the Java Virtual Machine (JVM). Kotlin is officially supported by Google as a first-class language for Android app development since 2017. Kotlin has many features that make it a great choice for Android app development, such as interoperability with Java, null safety, coroutines, extension functions, data classes, and more. In this article, we will explore 12 top Kotlin features that can enhance your Android app development process and make your code more readable, maintainable, and efficient.
1. Interoperability with Java: Kotlin is fully interoperable with Java, which means you can use existing Java libraries, frameworks, and tools in your Kotlin code without any hassle. You can also mix Kotlin and Java code in the same project and call Kotlin code from Java and vice versa. This makes it easy to migrate your existing Java code to Kotlin gradually or use Kotlin for new features in your existing Java project.
2. Null Safety: Kotlin has a built-in null safety feature that prevents null pointer exceptions, which are one of the most common causes of crashes in Android apps. Kotlin distinguishes between nullable and non-null types and enforces you to check for null values before using them. You can also use the safe call operator (?.) or the Elvis operator (?:) to handle null values gracefully.
3. Coroutines: Coroutines are a way of writing asynchronous and non-blocking code in Kotlin. Coroutines allow you to perform multiple tasks concurrently without blocking the main thread, which improves the responsiveness and performance of your app. You can use coroutines to handle network requests, database operations, background tasks, etc. Coroutines are also easy to write and read, as they use a sequential and suspending style of coding.
4. Extension Functions: Extension functions are a way of adding new functionality to existing classes without modifying them or creating subclasses. You can define extension functions for any class, even if you don’t have access to its source code. Extension functions are useful for adding utility methods or customizing the behavior of existing classes.
5. Data Classes: Data classes are a way of creating classes that mainly hold data and provide some basic functionality, such as getters, setters, equals, hashCode, toString, etc. You can create data classes by adding the keyword data before the class declaration. Data classes are useful for representing model objects or data transfer objects in your app.
6. Destructuring Declarations: Destructuring declarations are a way of unpacking multiple values from a single object or collection into separate variables. You can use destructuring declarations to simplify your code and make it more readable. For example, you can use destructuring declarations to assign the properties of a data class or the elements of a list or a pair to separate variables.
Continue reading 12 Top Kotlin Features to Enhance Android App Development Process
3 notes · View notes
devleader · 30 days
Video
undefined
tumblr
When using flag enums in CSharp, did you know...
When we call ToString() on a flags enum value, it will print out each of the flag values being matched!
This is a huge readability boost, especially when debugging. Mentally flip-flopping between numeric and string representations can be tiring, so having it prepared for us in a convenient way is awesome!
Check out the full video: https://youtu.be/_yUOrzTCpGU
📨 Sign up for my FREE email newsletter
🗣️ Share with your network!
When using flag enums in CSharp, did you know...
When we call ToString() on a flags enum value, it will print out each of the flag values being matched!
This is a huge readability boost, especially when debugging. Mentally flip-flopping between numeric and string representations can be tiring, so having it prepared for us in a convenient way is awesome!
👇Want the full video? Comment below! 👇
📨 Sign up for my FREE email newsletter
🗣️ Share with your network!
0 notes
9hikers · 3 months
Text
Tumblr media
if you are so shit at coding that you rely on Eclipse to generate a toString method, i am begging you to choose a different career path
0 notes
codeshive · 3 months
Text
CSC248 Lab Assignment – Review of OOP solved
1.1 Class Land has the following attributes and methods: Attributes: • id • owner name • house type • area i. Write the Land class and the following methods: a) Default constructor. b) Normal constructor that set all data with values given through the parameter. c) Mutator/Setter method d) Retriever method for each attribute. e) Printer method using toString()defined method. f) A processor method…
Tumblr media
View On WordPress
0 notes
codingprolab · 3 months
Text
CSC248 Lab Assignment – Review of OOP
1.1 Class Land has the following attributes and methods: Attributes: • id • owner name • house type • area i. Write the Land class and the following methods: a) Default constructor. b) Normal constructor that set all data with values given through the parameter. c) Mutator/Setter method d) Retriever method for each attribute. e) Printer method using toString()defined method. f) A processor method…
Tumblr media
View On WordPress
0 notes
fruitmouse · 4 months
Text
ohhh C#. what’s .ToString() i’ll kill you
0 notes
codemaster-or-kr · 4 months
Text
40. "프로그램언어 다트(Dart)에서의 최신 트렌드와 미래"
다트(Dart) 프로그래밍 언어란? 다트(Dart)는 구글에서 개발한 프로그래밍 언어로, 모바일, 웹, 서버 개발을 위해 탄생했습니다. 다트는 크로스 플랫폼 앱 개발 프레임워크인 플러터(Flutter)의 주요 프로그래밍 언어로 널리 사용되고 있습니다. 다트(Dart)의 최신 트렌드 다트는 계속해서 업데이트되고 있으며, 이로 인해 편리하고 신뢰성 있는 개발 환경을 제공하고 있습니다. 최근에는 널-세이프(Null Safety)을 지원하는 것이 대표적인 트렌드입니다. 널-세이프는 프로그램에서 null 오류를 피하도록 도와주어 개발자가 더욱 안전하게 코드를 작성할 수 있습니다. void main() { int a; print(a?.toString()); } 다트(Dart)의 미래 다트는 플러터와 함께 모바일, 웹, 데스크톱에서 사용되며, 구글뿐 아니라 다른 기업들에서도 채택하고 있습니다. 플러터와 함께 다트의 중요성은 계속 커질 것으로 보이고, 알고리즘 개선, 성능 향상, 개발자 경험 개선 등에 주력하고 있습니다. 다트는 이미 많은 개발자와 기업들에게 인정받은 프로그래밍 언어로 그 성장세가 계속될 것으로 예상됩니다. 다트에서의 예제 코드의 사용법 아래는 다트에서의 간단한 예제 코드입니다. void main() { print('Hello, Dart!'); } 이 코드는 'Hello, Dart!'라는 문자열을 출력합니다. 'void main() {' 로 시작하는 부분은 메인 함수를 정의하는 부분이며, 이 메인 함수가 프로그램의 시작점이 됩니다. 'print'는 출력을 위한 함수이며, 괄호 안의 문자열을 출력하게 됩니다. Read the full article
0 notes
myprogrammingsolver · 5 months
Text
Chapter 8 Lab More Classes and Objects
Lab Objectives Be able to write a copy constructor Be able to write equals and toString methods Be able to use objects made up of other objects (Aggregation) Be able to write methods that pass and return objects Introduction We discussed objects in Chapter 6 and we modeled a television in the Chapter 6 lab. We want build on that lab, and work more with objects. This time, the object that we are…
Tumblr media
View On WordPress
0 notes
moinotatku · 5 months
Text
Lista jednokie. (lb6)(CustomList, Main)
CustomList:
import java.util.AbstractList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.stream.Stream;
public class CustomList<T> extends AbstractList<T> {
    private class Node {
        public Node next;
        public T value;
        public Node(T value) {
            this.next = null;
            this.value = value;
        }
    }
    private Node head, tail;
    private int size = 0;
    public CustomList() {
        this.head = null;
        this.tail = null;
    }
    @Override
    public int size() {
        return size;
    }
    @Override
    public T get(int index) {
        Node n = head;
        for (int i=0; i<index; i++){
            n = n.next;
            if(n == null) {
                throw new NoSuchElementException("index is out of bounds");
            }
        }
        return n.value;
    }
    public void addLast(T value) {
        if (tail == null) {
            assert head == null;
            tail = new Node(value);
            head = tail;
        } else {
            tail.next = new Node(value);
            tail = tail.next;
        }
        size++;
    }
    public void addFirst(T value) {
        if (head == null) {
            assert tail == null;
            head = new Node(value);
            tail = head;
        } else {
            Node newHead = new Node(value);
            newHead.next = head;
            head = newHead;
        }
        size++;
    }
    public T getLast() {
        if (tail == null) throw new NoSuchElementException("List is empty");
        return tail.value;
    }
    public T getFirst() {
        if (head == null) throw new NoSuchElementException("List is empty");
        return head.value;
    }
    public T removeLast() {
        if (tail == null) throw new NoSuchElementException("Trying to remove element from empty list");
        assert head != null;
        T result;
        if (head == tail) {
            result = tail.value;
            head = tail = null;
        } else {
            Node n = head;
            while (n.next != tail) {
                n = n.next;
            }
            tail = n;
            n.next = null;
            result = n.value;
        }
        size--;
        return result;
    }
    @Override
    public Iterator<T> iterator() {
        return new Iterator<T>() {
            Node n = head;
            @Override
            public boolean hasNext() {
                return n != null;
            }
            @Override
            public T next() {
                T result = n.value;
                n = n.next;
                return result;
            }
        };
    }
    @Override
    public Stream<T> stream(){
        Stream.Builder<T> builder = Stream.builder();
        for(T i : this){
            builder.accept(i);
        }
        return builder.build();
    }
    public T removeFirst() {
        if (head == null) throw new NoSuchElementException("Trying to remove element from empty list");
        T result = head.value;
        head = head.next;
        size--;
        return result;
    }
    @Override
    public String toString() {
        if (head == null) return "CustomList []";
        StringBuilder result = new StringBuilder("CustomList [ ");
        Node n = head;
        while (n != null) {
            result.append(n.value).append(" ");
            n = n.next;
        }
        result.append("] size=");
        result.append(size);
        return result.toString();
    }
    @Override
    public boolean add(T t) {
        this.addLast(t);
        return true;
    }
    public static <S> List<S> filterByClass(List<S> list, Class<?> cls){
//        List<S> output = new CustomList<>();
//
//        for(S elem : list){
//            if(cls.isInstance(elem)){
//                output.add(elem);
//            }
//        }
//
//        return output;
        return list.stream().filter(cls::isInstance).toList();
    }
}
Main:
public class Main {
    public static void main(String[] args) {
        { // test adding last
            CustomList<Integer> list = new CustomList<>();
            System.out.println(list);
            list.addLast(5);
            System.out.println(list);
            list.addLast(4);
            System.out.println(list);
        }
        { // test adding first
            CustomList<Integer> list = new CustomList<>();
            System.out.println(list);
            list.addFirst(6);
            System.out.println(list);
            list.addFirst(9);
            System.out.println(list);
        }
//        { // test throwing exception
//            CustomList<Integer> list = new CustomList<>();
//            System.out.println(list.getLast());
//        }
        {
            CustomList<Integer> list = new CustomList<>();
            for (int i = 0; i < 10; i++) list.addLast(i);
            System.out.println(list);
          /* for (int i = 0; i < 10; i++) {
                list.removeLast();
                System.out.println(list);*/
        //}
            for (int i = 0; i < list.size(); i++)
                System.out.print(list.get(i));
            for(Integer i : list){
                System.out.println(i);
            }
            list.stream()
                    .map(i -> i+10)
                    .forEach(System.out::println);
        }
        {
            CustomList<Object> list = new CustomList<>();
            list.addLast(0.123f);
            list.addLast(.99d);
            list.addLast("Hello!");
            var list2 = CustomList.filterByClass(list, Number.class);
            System.out.println(list2);
        }
    }
}
0 notes
jesprotech · 6 months
Text
When thinking about Java fields we use-site target in Kotlin
One of the greatest strong points of Kotlin can also be its weakness. When we talk about data classes today, and in the same way java records, we tend to focus, at least many people I know do, on the complete elimination of the boilerplate code. Boilerplate code has been something that has been annoying developers for ages. It exists not only in Java, but other languages have that as well. If we think about creating data access objects any way, it doesn��t really matter if we do it in Kotlin or Java or any other language. Frequently we repeat the same process: repository creation, service and controller. A lot of what we do is boilerplate any way still. However boilerplate code may have been a part of the decision to create data classes or java records, a more important paradigm of software engineering was the actual focal point of creating these types of data structures. It all boils down to immutability or in any case the possibility thereof. Let’s rollback the time and go back to 1995 where we started at some point to create data structures where we would specify different things. We would define the fields, the getters, the setters, the properties, the accessors, the attributes and the parameters in a way to be able to pass our arguments to either the methods, the functions or the contructors. Fot this part we will have some fun programming using the characters of the mid-80’s series: The Golden Girls. Having said this, let’s see how a class would look like for about 15 years:
public class GoldenGirlsJava { public String goldenGirl1; private final String goldenGirl2; private final String goldenGirl3; private final String goldenGirl4; public GoldenGirlsJava() { this.goldenGirl1 = "Dorothy Zbornak"; this.goldenGirl2 = "Rose Nylund"; this.goldenGirl3 = "Blanche Devereaux"; this.goldenGirl4 = "Sophia Petrillo"; } public GoldenGirlsJava( String goldenGirl1, String goldenGirl2, String goldenGirl3, String goldenGirl4 ) { this.goldenGirl1 = goldenGirl1; this.goldenGirl2 = goldenGirl2; this.goldenGirl3 = goldenGirl3; this.goldenGirl4 = goldenGirl4; } public String getGoldenGirl1() { return goldenGirl1; } public void setGoldenGirl1(String goldenGirl1) { this.goldenGirl1 = goldenGirl1; } public String getGoldenGirl2() { return goldenGirl2; } public String getGoldenGirl3() { return goldenGirl3; } public String getGoldenGirl4() { return goldenGirl4; } @Override public String toString() { return "GoldenGirlsJava{" + "goldenGirl1='" + goldenGirl1 + '\'' + ", goldenGirl2='" + goldenGirl2 + '\'' + ", goldenGirl3='" + goldenGirl3 + '\'' + ", goldenGirl4='" + goldenGirl4 + '\'' + '}'; } }
This was a tremendous amount of code to type in only to create two contructors. Although the hashcode and equals weren’t necessarily a must in all occasions, we almost always had to implememt a no arguments contructor next to a more generalistic constructor. The good thing about creating all of this boilerplate code is that we knew very clearly how everything would look like after compiling to bytecode. However, and in any case, boilerplate code was always a contentious issue for many developers and so in 2009, lombok came along and revolutionized the way we create data structures. It introduced the concept of using an annotation processor and interpreting specific annotations that would give the qualities we needed for our classes and so a lombok annotated class would look like this:
@Getter @Setter @AllArgsConstructor @ToString public class GoldenGirlsLombok { public String goldenGirl1; private final String goldenGirl2; private final String goldenGirl3; private final String goldenGirl4; public GoldenGirlsLombok() { this.goldenGirl1 = "Dorothy Zbornak"; this.goldenGirl2 = "Rose Nylund"; this.goldenGirl3 = "Blanche Devereaux"; this.goldenGirl4 = "Sophia Petrillo"; } }
And for a while, people were very happy about Lombok! Finally the weight of having to create all of that boilerplate code was gone. But that felling endured for about 7 years, when a new player arrived and this time it was something the software development industry didn’t expected. It was called Kotlin and in 2016 it debuted with the immediate introduction of data classes. Our golden girls implementation in Kotlin would now look like this:
data class GoldenGirls( var goldenGirl1: String = "Dorothy Zbornak", private val goldenGirl2: String = "Rose Nylund", private val goldenGirl3: String = "Blanche Devereaux", private val goldenGirl4: String = "Sophia Petrillo" )
Although Kotlin slowly started gathering fans, Java on the other hand realized that something else was in the market and some developments on that side started gaining some steam like project Loom which had been in the making but also left in the back burner for a while. That is why, with the release of Java 14 in 20202, Java introduced java records, and data structures in Java would now look like this: public record GoldenGirlsRecord( String goldenGirl1, String goldenGirl2, String goldenGirl3, String goldenGirl4 ) { public GoldenGirlsRecord() { this( "Dorothy Zbornak", "Rose Nylund", "Blanche Devereaux", "Sophia Petrillo" ); } }
And to this day code simplification and code reduction seems only to continue. However with the reduction of the boilerplate code, the concepts of fields, getters, setters, properties, accessors, attributes and parameters became far less visual and less easy to map in our minds. Whether we like it or not those concepts are still how the JVM works and organizes code with the bytecode. But code oversimplification is really about making code easier to read and in the case of data classes and java records the idea is also to create data structures that are immutable or partially immutable. Java records are truly immutable in the sense that all values it contains or references it contains cannot be modified. Kotlin data classes can be also truly immutable for the same reasons but they don’t have to which in a way gives permission to developers to create complicated and worst of all, mutable code anyway. In any case this is all good until we then need to work with frameworks like the Spring Framework, which rely heavily on annotations. Here is an example:
@Entity @Table(name = "shelf_case") data class Case( @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) val id: Long?, var designation: String?, var weight: Long? ) { constructor() : this(0L, null, null) override fun toString(): String { return super.toString() } }
This example works fine. To the unsuspecting eye, there isn’t a lot special going on here. This works in Kotlin, just in the same way as it would work in Java. But now let’s have a look at a similar example, but this time with Jackson annotations:
data class AccountNumbersPassiveDto( @NotNull val accountNumberLong: Long?, val accountNumberNullable: Long?, @DecimalMax(value = "10") @DecimalMin(value = "5") val accountNumber: BigDecimal, val accountNumberEven: Int, val accountNumberOdd: Int, @Positive val accountNumberPositive: Int, @Negative val accountNumberNegative: Int, @DecimalMax(value = "5", groups = [LowProfile::class]) @DecimalMax(value = "10", groups = [MiddleProfile::class]) @DecimalMax(value = "15", groups = [HighProfile::class]) @DecimalMax(value = "20") val accountNumberMaxList:Int )
This example will fail and the reason for that is that in Kotlin, there is no way to tell the compiler where exactly to we want our annotation to be applied to. In the previous example with annotation @Entity, which is a jakarta persistence annotation, the annoations are applied correctly to the fields. If we decompile that code we’ll find this:
public final class Case { @Id @GeneratedValue( strategy = GenerationType.SEQUENCE ) @Nullable private final Long id; @Nullable private String designation; @Nullable private Long weight;
But for the latter, which is a jakarta validation example, we find this:
public final class AccountNumbersPassiveDto { @Nullable private final Long accountNumberLong; @Nullable private final Long accountNumberNullable; @NotNull private final BigDecimal accountNumber; private final int accountNumberEven; private final int accountNumberOdd;
This means that AccountNumbersDto has not been affected by those annotations on its fields. We were just lucky in the first example. It might have actually also failed. In order to specify where our annotation needs to go to, Kotlin gives us the possibility to use use-site targets as prefix to any annotation. The requirement is of course that conditions are met. In this case, one way to fix this is to prefix all of the annotations with @field like this:
data class AccountNumbersPassiveDto( @field:NotNull val accountNumberLong: Long?, val accountNumberNullable: Long?, @field:DecimalMax(value = "10") @field:DecimalMin(value = "5") val accountNumber: BigDecimal, val accountNumberEven: Int, val accountNumberOdd: Int, @field:Positive val accountNumberPositive: Int, @field:Negative val accountNumberNegative: Int, @field:DecimalMax(value = "5", groups = [LowProfile::class]) @field:DecimalMax(value = "10", groups = [MiddleProfile::class]) @field:DecimalMax(value = "15", groups = [HighProfile::class]) @field:DecimalMax(value = "20") val accountNumberMaxList:Int )
If we now try to decompile the resulting bytecode using IntelliJ, we’ll find that it results in this code in Java:
public final class AccountNumbersPassiveDto { @NotNull @Nullable private final Long accountNumberLong; @Nullable private final Long accountNumberNullable; @DecimalMax("10") @DecimalMin("5") @org.jetbrains.annotations.NotNull
This means that the annotations have been applied to field and that our code works as it is supposed to.
You can probably imagine at this point that people who have been working on Java for a long time, will have no problem in adapting to Kotlin because we all know what fields, parameters, properties, etc, are. What we observe today and I witness that too, is that it seems like the code simplification has a potential to backfire. There have been quite a few occasions where I have become aware of the time spent in projects trying to figure how why in some projects or modules, the annotations just don’t seem to work. And it all seems to boil down to not making use of the use-site targets. My theory on that is that most likely, new generations of developers will look at things that my generation didn’t think was complicated and learned out of instinct, as really complicated material. Such is the case with use-site targets. These used to be things that we could very easily visualize. However in current times, the generated confusion with this seems to be delaying projects from being developed on time in some occasions. I wouldn’t be able to generalize of course but there is potential for good and there is potential for bad with java records and data classes. How data classes and records will shape our future is hard to tell, but one thing that is clear is that because of this problematic, other frameworks are betting on going completely annotation free as is the case with Ktor.
I have created documentation on this on Scribed: Fields-in-Java-and-Kotlin-and-What-to-Expectand also on slide-share: fields-in-java-and-kotlin-and-what-to-expect.
You can also find the examples I’ve given on GitHub. The golden girls example can be found here:jeorg-kotlin-test-drives and the jakarta persistence and validation annotations examples can be found here: [jeorg-spring-master-test-drives][https://github.com/jesperancinha/jeorg-spring-master-test-drives).
Finally I also created a video about this on YouTube that you can have a look at right over here:
youtube
Have a good one everyone!
0 notes