设计模式学习之单例模式

特点 单例模式就是确保在系统中只在一个实例提供功能。单例有好几种写法,主要有饿汉式、懒汉式、静态方法内部类、注册式单例。 饿汉式 饿汉式单例就是在类定义时就已经将实例进行了初始化,在系统调用时可以直接返回不需要再实例化。示例代码如下: public class Hungry { private Hungry() { } private static final Hungry INSTANCE = new Hungry(); public static Hungry getInstance() { return INSTANCE; } } 饿汉式的优点是提前进行初始化,线程安全。缺点是在系统未调用的情况下占用了内存空间,是以空间换取时间的样例 懒汉式 懒汉式就是在使用才对对象实例进行初始化,达到了延迟加载的目的。示例代码如下: public class LazyOne { private LazyOne() { } private static LazyOne instance = null; public static LazyOne getInstance() { if (instance == null) { instance = new LazyOne(); } return instance; } } 懒式式优化点使用时实例化,延迟加载。缺点是存在线程安全问题 ...

2018-06-05 ·  (🌟Updated: 2019-06-26) · 3 min · 512 words · tomyli

Idea中vim键的映射

Idea中IdeaVim插件可以让我们在Idea中使用vi的按键来进行操作,但是原生的配置只带有一些基本的移动操作。需要在~/.ideavimrc文件中进行Idea的动作映射来发挥它们的最大力量。 Key Description kj gt VimBack gT VimForward gd GotoDeclaration gf GotoTypeDeclaration gh QuickJavaDoc gs GotoSymbol gi GotoImplementation gu FindUsages gj IntroduceVariable leader w d ActivateDatabaseToolWindow leader ' ActivateTerminalToolWindow leader w r ActivateRedisServersToolWindow leader w m ActivateMavenProjectsToolWindow leader w a HideActiveWindow leader w w HideAllWindows leader w p ActivateProjectToolWindow leader w s ActivateStructureToolWindow leader w v ActivateVersionControlToolWindow leader w h h Go to left window leader w l l Go to right window leader w k k Go to window up leader w j j Go to window down leader w V v Split Window Vertically leader w - s Split Winodw Horizontally leader w c c Close current window leader w o o Close all window except current leader GotoAction leader c c GotoClass leader c r CopyReference leader c p CopyPaths leader f f GotoFile leader f d DashLauncherAction leader b b RecentFiles leader b p FileStructurePopup leader b u ReopenClosedTab leader d d Debug leader d D DebugClass leader d j JRebel leader l l EvaluateExpression leader t t ToggleLineBreakpoint leader r r Run leader r R RunClass leader i m ImplementMethods leader e e ShowErrorDescription leader e n GotoNextError leader R :source ~/.ideavimrc leader g s Vcs.QuickListPopupAction leader r p ReplaceInPath zO ExpandAllRegions zo ExpandRegion zc CollapseRegion zC CollapseAllRegions fj emacsIDEAs.AceJump fw emacsIDEAs.AceJumpWord ff CommentByLineComment fb CommentByBlockComment gd GotoDeclaration gf GotoTypeDeclaration gh QuickJavaDoc gs GotoSymbol gi GotoImplementation gu FindUsages gj IntroduceVariable ,, ReformatCode ,r RenameElementi Back Forward leader R reload ~/.ideavimrc leader a l :actionlist leader g s Vcs.QuickListPopupAction leader s p FindInPath leader r p ReplaceInPath , c r Revert change , c t Close other tab

2018-05-14 ·  (🌟Updated: 2019-06-26) · 2 min · 272 words · tomyli

title = “2020-ARTS-打卡第十五天” lastmod = 2026-01-26T15:43:06+08:00 tags = [“arts”, “java”, “leetcode”] categories = [“arts”] draft = false author = “tomyli” +++ Algorithm 题目 题目描述 求一个数的N次幂 题目解答 public class MyPow { public double doPow(double x, int n) { if(x == 0) { return 0; } if(x == 1 || n == 0) { return 1; } if(n == 1) { return x; } long b = n; if(b < 0) { x = 1 / x; b = -b; } double res = 1.0; while(b > 0) { if((b & 1) == 1) { res *= x; } x *= x; b >>= 1; } return res; } } Review Tip Share

(🌟Updated: 2026-01-26) · 1 min · 111 words · Me