swift java api,在Java中比较Swift与接口中的协议

I'm going through the iOS tutorial from Apple developer page.

It seem to me that protocol and interface almost have the same functionality.

Are there any differences between the two?

the difference usage in project?

Updated

Yes, I did read the link above and I'm still not sure what the differences and usage between protocol and interface. When I ask question like this, I would like to see a simple explanation about the topic. Sometime it could be tough to get everything from the documentation.

解决方案

Essentially protocols are very similar to Java interfaces except for:

Swift protocols can also specify properties that must be implemented (i.e. fields)

Swift protocols need to deal with value/reference through the use of the mutating keyword (because protocols can be implemented by structs and classes)

you can combine protocols at any point with the protocol<> keyword. For example, declaring a function parameter that must adhere to protocol A and B as:

.

func foo ( var1 : protocol ){}

These are the immediately apparent differences for a Java developer (or at least what I've spotted so far).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值