Skip to content

Instantly share code, notes, and snippets.

View orange1988's full-sized avatar
💭
Vivalavida

Orange orange1988

💭
Vivalavida
  • China
View GitHub Profile
@orange1988
orange1988 / Kotlin和Java的单例模式.md
Created September 30, 2018 13:13
Kotlin和Java的单例模式

单例模式,一直以来是我们在日常开发中最常用的一种设计模式,更是面试中非常重要,也非常容易被问到的问题。在日常开发中,大家常用的语言还是Java,但今天我给大家带来的是在Kotlin语言中,单例模式是怎么编写的,并且会对比Java方式,并说明每种方式的优缺点。

下面会列举5种最为常见的单例模式做对比:

1.饿汉式 2.懒汉式 3.同步锁式 4.双重检测式 5.内部类式

import java.util.Scanner;
public class BitwiseOperator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("請輸入數字: ");
int inputedNumber = scanner.nextInt();
System.out.println("是否為奇數? " + ((inputedNumber&1) != 0 ? '是' : '否'));
}
}
package com.example.android.supportv7.widget.decorator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
public class DividerItemDecoration extends RecyclerView.ItemDecoration {
@orange1988
orange1988 / Android 命名规范.md
Last active December 19, 2022 03:43
Android 命名规范

在讲解命名规范前,先初略介绍下当前主要的标识符命名法和英文缩写规则。

标识符命名法

标识符命名法最要有四种:

  1. 驼峰(Camel)命名法:又称小驼峰命名法,除首单词外,其余所有单词的第一个字母大写。
  2. 帕斯卡(pascal)命名法:又称大驼峰命名法,所有单词的第一个字母大写
  3. 下划线命名法:单词与单词间用下划线做间隔。
  4. 匈牙利命名法:广泛应用于微软编程环境中,在以Pascal命名法的变量前附加小写序列说明该变量的类型。 量的取名方式为:<scope_> + <prefix_> + 范围前缀,类型前缀,限定词。
@orange1988
orange1988 / PagerAdapterDemo
Last active September 30, 2018 12:32
android viewpager demo
package com.orange1988.photoselector.adapter;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import com.orange1988.photoselector.entity.PhotoEntity;
import com.orange1988.photoselector.view.PreviewItemVIew;