Skip to content

Instantly share code, notes, and snippets.

View Mercandj's full-sized avatar
😀
Working on Android Apps

Jonathan Mercandalli Mercandj

😀
Working on Android Apps
View GitHub Profile
public interface Response {
int getHttpCode();
}
public final class Success implements Response {
private final int httpCode;
@NotNull private final String data;
public int getHttpCode() {
return this.httpCode;
sealed class Response(open val httpCode: Int)
data class Success(
override val httpCode: Int,
val data: String
) : Response(httpCode = httpCode)
data class Fail(
override val httpCode: Int
) : Response(httpCode = httpCode)
public abstract class Response {
private final int httpCode;
public int getHttpCode() {
return this.httpCode;
}
private Response(int httpCode) {
this.httpCode = httpCode;
}
sealed class Response
data class Success(
val data: String
) : Response()
data object Failed : Response()
@Mercandj
Mercandj / Response.kt
Last active April 29, 2024 14:42
medium_article_kotlin_sealed_class_enum.kt
enum class Response {
SUCCESS,
FAIL
}
@Mercandj
Mercandj / Response.kt
Last active April 29, 2024 16:41
medium_article_kotlin_sealed_class_bad
sealed interface Response {
val httpCode: Int
}
data class Success(
override val httpCode: Int,
val data: String
) : Response
data class Fail(
@Mercandj
Mercandj / bad.kt
Created April 29, 2024 14:37
medium_article_kotlin_sealed_class_1
sealed class Response {
abstract val httpCode: Int
}
data class Success(
override val httpCode: Int,
val data: String
) : Response()
import UIKit
import SwiftUI // <-- Add SwiftUI import
class HelloWorldView: UIView {
// UIView code here
struct HelloWorldView_Preview: PreviewProvider { // <-- Add the preview definition
static var previews: some View {
Preview()
@Mercandj
Mercandj / HelloWorldView.swift
Last active January 7, 2023 17:01
swiftui_preview_with_ui_view
import UIKit
class HelloWorldView: UIView {
private lazy var title = createTitle()
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(title)
}
@Mercandj
Mercandj / MainActivity.kt
Last active December 9, 2022 17:49
Memory leak medium article
class MainActivity : AppCompatActivity() {
private val listener = Manager.Listener {
Log.d("memory_leak", "Use largeObject to avoid compiler opti $largeObject")
}
private var largeObject = (0..4_000).map {
Bitmap.createBitmap(1000, 1000, Bitmap.Config.ARGB_8888)
}
override fun onCreate(savedInstanceState: Bundle?) {