René's URL Explorer Experiment


Title: 「Effective Java」Notes · Issue #6 · Sitrone/LeetcodeInJava · GitHub

Open Graph Title: 「Effective Java」Notes · Issue #6 · Sitrone/LeetcodeInJava

X Title: 「Effective Java」Notes · Issue #6 · Sitrone/LeetcodeInJava

Description: Item 3 单例模式 饿汉式 static final method public class Singleton{ //类加载时就初始化 private static final Singleton instance = new Singleton(); private Singleton(){} public static Singleton getInstance(){ return instance; } } 注意,这种方法实现序列化接口的时候会有问题 在序列...

Open Graph Description: Item 3 单例模式 饿汉式 static final method public class Singleton{ //类加载时就初始化 private static final Singleton instance = new Singleton(); private Singleton(){} public static Singleton getInstance(){ return...

X Description: Item 3 单例模式 饿汉式 static final method public class Singleton{ //类加载时就初始化 private static final Singleton instance = new Singleton(); private Singleton(){} public static Singleton getInstance(){ return...

Opengraph URL: https://github.com/Sitrone/LeetcodeInJava/issues/6

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"「Effective Java」Notes","articleBody":"## Item 3 单例模式\n### 饿汉式 `static final method`\n\n``` java\npublic class Singleton{\n    //类加载时就初始化\n    private static final Singleton instance = new Singleton();\n\n    private Singleton(){}\n\n    public static Singleton getInstance(){\n        return instance;\n    }\n}\n```\n\n**注意,这种方法实现序列化接口的时候会有问题**  \n- 在序列化后,再经过反序列化会得到一个不同的对象,需要在单例类中加入readResolve()方法,才能防止反序列化生成的对象与原有对象不是同一对象的问题 , 具体实现如下:\n\n``` java\npublic class SingletonSerizlizable implements Serializable{\n private static final SingletonSerizlizable INSTANCE=new SingletonSerizlizable();\n private SingletonSerizlizable(){};\n public static SingletonSerizlizable getInstance()\n {\n   return INSTANCE;\n }\n\nprivate Object readResolve()\n{\n return INSTANCE;//依旧返回最初创建的对象,不再创建新对象\n}\n public static void main(String[] args) {\n   // TODO Auto-generated method stub\n\n }\n\n}\n```\n### 静态内部类 `static nested class`\n\n``` java\npublic class Singleton {  \n    private static class SingletonHolder {  \n        private static final Singleton INSTANCE = new Singleton();  \n    }  \n    private Singleton (){}  \n    public static final Singleton getInstance() {  \n        return SingletonHolder.INSTANCE; \n    }  \n}\n```\n### 枚举\n\n``` java\npublic enum Elvis {\n    INSTANCE;\n\n    public void levaveTheBuilding(){\n        System.out.println(\"leave ...\");\n    }\n\n    public static void main(String[] args){\n        Elvis singleton = Elvis.INSTANCE;\n        singleton.levaveTheBuilding();\n    }\n}\n```\n#### Effective Java作者最推荐的方式,多线程安全,简单,序列化和反序列化没有问题。\n\n\u003e Enum constants are serialized differently than ordinary serializable or externalizable objects. The serialized form of an enum constant consists solely of its name; field values of the constant are not present in the form. To serialize an enum constant, ObjectOutputStream writes the value returned by the enum constant’s name method. To deserialize an enum constant, ObjectInputStream reads the constant name from the stream; the deserialized constant is then obtained by calling the java.lang.Enum.valueOf method, passing the constant’s enum type along with the received constant name as arguments. Like other serializable or externalizable objects, enum constants can function as the targets of back references appearing subsequently in the serialization stream. The process by which enum constants are serialized cannot be customized: any class-specific writeObject, readObject, readObjectNoData, writeReplace, and readResolve methods defined by enum types are ignored during serialization and deserialization. Similarly, any serialPersistentFields or serialVersionUID field declarations are also ignored–all enum types have a fixedserialVersionUID of 0L. Documenting serializable fields and data for enum types is unnecessary, since there is no variation in the type of data sent.  \n\n---\n### Ref\n1.  [Effective Java 第三条单例模式的序列化的思考](https://jssyjam.github.io/2016/04/28/Effective-Java-%E7%AC%AC%E4%B8%89%E6%9D%A1%E5%8D%95%E4%BE%8B%E6%A8%A1%E5%BC%8F%E7%9A%84%E5%BA%8F%E5%88%97%E5%8C%96%E7%9A%84%E6%80%9D%E8%80%83/)  \n2. [如何正确地写出单例模式](http://wuchong.me/blog/2014/08/28/how-to-correctly-write-singleton-pattern/)\n","author":{"url":"https://github.com/Sitrone","@type":"Person","name":"Sitrone"},"datePublished":"2016-10-26T14:21:54.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/6/LeetcodeInJava/issues/6"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:9580f4ee-2523-e4be-61e3-27a9a187da50
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCE4C:36B458:782399:A32BF4:6A5FD6DE
html-safe-nonce2f54a835f881309142b1b7d167472ddc98cc0621a5bda29cbc5332afbe1fd203
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRTRDOjM2QjQ1ODo3ODIzOTk6QTMyQkY0OjZBNUZENkRFIiwidmlzaXRvcl9pZCI6IjE1MjM5NTA5MjM1MDA0NzYxMjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac883b3124c30229e9b822060f840a784939f7f1c6660027714cea546b890c745b
hovercard-subject-tagissue:185407999
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/Sitrone/LeetcodeInJava/6/issue_layout
twitter:imagehttps://opengraph.githubassets.com/bdfd0d12dc54c698c1a4d3090c6a05313368df318ad2e90f22701adcbb7188f6/Sitrone/LeetcodeInJava/issues/6
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/bdfd0d12dc54c698c1a4d3090c6a05313368df318ad2e90f22701adcbb7188f6/Sitrone/LeetcodeInJava/issues/6
og:image:altItem 3 单例模式 饿汉式 static final method public class Singleton{ //类加载时就初始化 private static final Singleton instance = new Singleton(); private Singleton(){} public static Singleton getInstance(){ return...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameSitrone
hostnamegithub.com
expected-hostnamegithub.com
None2a1904016bf220ad1311da188567b50f2c83d69b89a554fd8b017417589fbe29
turbo-cache-controlno-preview
go-importgithub.com/Sitrone/LeetcodeInJava git https://github.com/Sitrone/LeetcodeInJava.git
octolytics-dimension-user_id5569320
octolytics-dimension-user_loginSitrone
octolytics-dimension-repository_id61412709
octolytics-dimension-repository_nwoSitrone/LeetcodeInJava
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id61412709
octolytics-dimension-repository_network_root_nwoSitrone/LeetcodeInJava
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasef83c469daaa92993df0b1f479d525995ec8cc172
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/Sitrone/LeetcodeInJava/issues/6#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FSitrone%2FLeetcodeInJava%2Fissues%2F6
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FSitrone%2FLeetcodeInJava%2Fissues%2F6
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=Sitrone%2FLeetcodeInJava
Reloadhttps://github.com/Sitrone/LeetcodeInJava/issues/6
Reloadhttps://github.com/Sitrone/LeetcodeInJava/issues/6
Reloadhttps://github.com/Sitrone/LeetcodeInJava/issues/6
Sitrone https://github.com/Sitrone
LeetcodeInJavahttps://github.com/Sitrone/LeetcodeInJava
Notifications https://github.com/login?return_to=%2FSitrone%2FLeetcodeInJava
Fork 0 https://github.com/login?return_to=%2FSitrone%2FLeetcodeInJava
Star 3 https://github.com/login?return_to=%2FSitrone%2FLeetcodeInJava
Code https://github.com/Sitrone/LeetcodeInJava
Issues 6 https://github.com/Sitrone/LeetcodeInJava/issues
Pull requests 0 https://github.com/Sitrone/LeetcodeInJava/pulls
Actions https://github.com/Sitrone/LeetcodeInJava/actions
Projects https://github.com/Sitrone/LeetcodeInJava/projects
Wiki https://github.com/Sitrone/LeetcodeInJava/wiki
Security and quality 0 https://github.com/Sitrone/LeetcodeInJava/security
Insights https://github.com/Sitrone/LeetcodeInJava/pulse
Code https://github.com/Sitrone/LeetcodeInJava
Issues https://github.com/Sitrone/LeetcodeInJava/issues
Pull requests https://github.com/Sitrone/LeetcodeInJava/pulls
Actions https://github.com/Sitrone/LeetcodeInJava/actions
Projects https://github.com/Sitrone/LeetcodeInJava/projects
Wiki https://github.com/Sitrone/LeetcodeInJava/wiki
Security and quality https://github.com/Sitrone/LeetcodeInJava/security
Insights https://github.com/Sitrone/LeetcodeInJava/pulse
「Effective Java」Noteshttps://github.com/Sitrone/LeetcodeInJava/issues/6#top
Javahttps://github.com/Sitrone/LeetcodeInJava/issues?q=state%3Aopen%20label%3A%22Java%22
Noteshttps://github.com/Sitrone/LeetcodeInJava/issues?q=state%3Aopen%20label%3A%22Notes%22
https://github.com/Sitrone
Sitronehttps://github.com/Sitrone
on Oct 26, 2016https://github.com/Sitrone/LeetcodeInJava/issues/6#issue-185407999
Effective Java 第三条单例模式的序列化的思考https://jssyjam.github.io/2016/04/28/Effective-Java-%E7%AC%AC%E4%B8%89%E6%9D%A1%E5%8D%95%E4%BE%8B%E6%A8%A1%E5%BC%8F%E7%9A%84%E5%BA%8F%E5%88%97%E5%8C%96%E7%9A%84%E6%80%9D%E8%80%83/
如何正确地写出单例模式http://wuchong.me/blog/2014/08/28/how-to-correctly-write-singleton-pattern/
Javahttps://github.com/Sitrone/LeetcodeInJava/issues?q=state%3Aopen%20label%3A%22Java%22
Noteshttps://github.com/Sitrone/LeetcodeInJava/issues?q=state%3Aopen%20label%3A%22Notes%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.