{"id":37019925,"url":"https://github.com/state-machine-systems/dynamic-reference","last_synced_at":"2026-01-14T02:14:02.802Z","repository":{"id":31178073,"uuid":"34738551","full_name":"state-machine-systems/dynamic-reference","owner":"state-machine-systems","description":"Dynamically-scoped variables for Java","archived":false,"fork":false,"pushed_at":"2015-08-28T08:32:31.000Z","size":164,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-13T02:43:04.649Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/state-machine-systems.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-28T15:21:57.000Z","updated_at":"2015-04-28T19:40:12.000Z","dependencies_parsed_at":"2022-09-08T15:22:42.792Z","dependency_job_id":null,"html_url":"https://github.com/state-machine-systems/dynamic-reference","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/state-machine-systems/dynamic-reference","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/state-machine-systems%2Fdynamic-reference","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/state-machine-systems%2Fdynamic-reference/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/state-machine-systems%2Fdynamic-reference/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/state-machine-systems%2Fdynamic-reference/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/state-machine-systems","download_url":"https://codeload.github.com/state-machine-systems/dynamic-reference/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/state-machine-systems%2Fdynamic-reference/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T01:52:23.358Z","status":"online","status_checked_at":"2026-01-14T02:00:06.678Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2026-01-14T02:13:59.709Z","updated_at":"2026-01-14T02:14:02.797Z","avatar_url":"https://github.com/state-machine-systems.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Dynamically-scoped references offer a more disciplined alternative to global variables. They're a handy feature from\nthe Lisp family of languages.\n\nIn Java, `static` fields are equivalent to global variables, with all the bad stuff that entails. By contrast, you\ncreate a `DynamicReference` with an initial default value, which can be overridden inside a given block\nscope. Code inside the block (at any call depth) will automatically use the overridden value. After the block\nfinishes, the value reverts back.\n\nHere's an example of overriding a reference to `System.out`:\n\n    import com.statemachinesystems.util.DynamicReference;\n    import java.io.*;\n\n    ...\n\n    DynamicReference\u003cPrintStream\u003e out = new DynamicReference\u003c\u003e(System.out);\n\n    PrintStream log = new PrintStream(new File(\"out.log\"), \"UTF-8\");\n\n    void sayHello() {\n        out.get().println(\"Hello World!\");\n    }\n\n    ...\n\n    // write to standard output\n    sayHello();\n\n    ...\n\n    out.withValue(log, () -\u003e {\n        // write to the log file\n        sayHello();\n    });\n\nThis implementation is based on the `DynamicVariable` class from the Scala standard library.\n\n### Getting started\n\nThis library is in the Maven Central repo, so just add the following chunk to your pom.xml (or the equivalent for Gradle/SBT/whatever):\n\n    \u003cdependency\u003e\n        \u003cgroupId\u003ecom.statemachinesystems\u003c/groupId\u003e\n        \u003cartifactId\u003edynamic-reference\u003c/artifactId\u003e\n        \u003cversion\u003e1.0\u003c/version\u003e\n    \u003c/dependency\u003e\n\n\u0026copy; 2015 State Machine Systems Ltd. [Apache Licence, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstate-machine-systems%2Fdynamic-reference","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstate-machine-systems%2Fdynamic-reference","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstate-machine-systems%2Fdynamic-reference/lists"}