Skip to content

trigunam/tostring-implementation

Repository files navigation

TOSTRING IMPLEMENTATION

Maven build status Contributions welcome

This project is a library for any POJO class to implement a toString method without actually writing any implementation.

Now in Maven Central

Usage

@Override
public String toString() {
  return Utilities.toString(this);
}

The above will print the following output on a HelloToString class:

Addresses = [Bangalore, Karnataka, India], Id = 1, Name = Triguna, Now = 2021-9-4 13:56:37.967, 
Time taken to use toString method = 0.019 ms

Pattern

Given a class name and instance, the project will use the reflection from Java to fetch the getter methods for the given instance and execute it to print the methodName = methodValue in an appended string with comma-separated values.

This is a very generic implementation so anybody can use this code to write their toString implementation. The idea is to avoid implementing toString by writing your own implementation every time.

Please put your thoughts on the implementation so we can evolve as a project which will help every Java Developer.

Reviews from various stakeholders

Refer to Reviews from various stakeholders

Usage Guide in detail

Refer to Usage Guide for more details on the usage.