I have the following code in Dart programming language
class HttpResponse {
final int code;
final String? error;
HttpResponse.ok() : code = 200; <== This functionality
HttpResponse.notFound() <== This functionality
: code = 404,
error = 'Not found';
String toString() {
if (code == 200) return 'OK';
return 'ERROR $code ${error.toUpperCase()}';
}
}
How can I achieve this in Kotlin, I know that I can use static methods, however static methods don't have the purpose of initializing a class, is there a way where this can be achieved in Kotlin?