{"id":22202567,"url":"https://github.com/serras/boostrap-methods","last_synced_at":"2025-03-25T01:46:39.793Z","repository":{"id":264198320,"uuid":"887824089","full_name":"serras/boostrap-methods","owner":"serras","description":"Boostrap method for `copy`","archived":false,"fork":false,"pushed_at":"2024-11-22T14:57:53.000Z","size":64,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-30T03:28:00.652Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/serras.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-13T10:53:10.000Z","updated_at":"2024-11-22T14:57:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"0d7a12fc-a744-450d-beec-03de8bdd315a","html_url":"https://github.com/serras/boostrap-methods","commit_stats":null,"previous_names":["serras/boostrap-methods"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serras%2Fboostrap-methods","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serras%2Fboostrap-methods/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serras%2Fboostrap-methods/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serras%2Fboostrap-methods/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serras","download_url":"https://codeload.github.com/serras/boostrap-methods/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245383119,"owners_count":20606265,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-02T16:33:17.813Z","updated_at":"2025-03-25T01:46:39.774Z","avatar_url":"https://github.com/serras.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Boostrap method for `copy`\n\n\u003e An exploration of using `invokedynamic` for Kotlin data classes.\n\nThe `invokedynamic` opcode was introduced in Java 7 to support lambdas and dynamic languages.\nMore recently, it has become the way Java \"implements\" several functions for records, such\nas `toString` and `equals`, without having to generate loads of code for each record.\nSo why not use the same technique for our data classes?\n\nWe strongly recommend looking at [this post](https://www.baeldung.com/java-invoke-dynamic)\nto understand how `invokedynamic` works. The key point is to create a _boostrap method_ that\ngenerates the required code, which is then linked as if it had always been there.\nThe `DataCopy.kt` file in this repository shows that generating such a bootstrap method for\ndata classes is **feasible**.\n\n## Practical usage\n\nOnce this bootstrap method is available in the standard library, whenever we find a call\nof the form:\n\n```kotlin\nfoo.copy(bar = \"bye\")\n```\n\nwe should use `invokedynamic` to link the corresponding implementation. The arguments to\nthe boostrap method are a reference to the (data) class for which `copy` is called, and\nthe names of the properties which are given to the call.\n\n```\ninvokedynamic kotlin/internal/Bootstrap.copy Foo::class \"bar\"\n```\n\nThis technique solves the **forward compatibility** problem of data classes.\nThe `invokedynamic` instruction only requires the name of the properties to modify at\ncompile time, but knowing what are all the properties needed to call the constructor is\ndeferred until runtime.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserras%2Fboostrap-methods","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserras%2Fboostrap-methods","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserras%2Fboostrap-methods/lists"}