Access modifier summary-Smartphone application development (Java / Kotlin / Objective-C / Swift / C # / F #)

Introduction

One point of confusion when developing across different languages is access modifiers. This time, as a smartphone application development edition, we will investigate each access modifier for Java / Kotlin used for Android development, Objective-C / Swift used for iOS development, and C # / F # used for Xamarin, and summarize it as a comparison table. I tried it.

Comparison table

Access modifier Java Kotlin Objective-C Swift C# F#
open (not exist) (not exist) (not exist) Accessable from anywhere
* Added in Swift3
(not exist) (not exist)
public Accessable from anywhere Accessable from anywhere Accessable from anywhere Accessable from anywhere
※ただし別モジュールからの継承とオーバーライドは不可(Swift2まではAccessable from anywhere)
Can be accessed from anywhere Can be accessed from anywhere
package (not exist) (not exist) Accessable from within the same framework
* Private outside the framework
(not exist) (not exist) (not exist)
protected Accessable from class + derived class in the same package 継承したAccessable from class + derived class in the same package Accessable from the same class + derived class (not exist) Can be accessed from the same class + derived class (not exist)
protected internal (not exist) (not exist) (not exist) (not exist) Accessable from class + derived class in the same project (not exist)
internal (not exist) Accessable within the same module (not exist) Accessable within the same module Accessable within the same assembly Accessable within the same assembly
fileprivate (not exist) (not exist) (not exist) Can be accessed within the same file
* Added in Swift3
(not exist) (not exist)
private Accessable within the same scope
* You can also refer to the private variable of the inner class.
Accessable within the same scope Accessable within the same scope Accessable within the same scope
* Up to Swift2 can be accessed in the same file
Accessable within the same scope Accessable within the same scope
Not specified Accessable within the same package Same as public Same as protected Same as internal Same as private Same as public
* Let binding/do束縛ではSame as private

It seems that you need to be careful because the movement when you do not specify anything is wonderfully different.

reference

First time in Kotlin. I compared it with Java Access control from Swift 3 Objective-C access specifier

Recommended Posts

Access modifier summary-Smartphone application development (Java / Kotlin / Objective-C / Swift / C # / F #)
Access modifier [Java]
Access modifier summary-JVM language edition (Java / Groovy / Scala / Kotlin)
Access Teradata from a Java application