博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
observable_Java Observable countObservers()方法与示例
阅读量:2529 次
发布时间:2019-05-11

本文共 2278 字,大约阅读时间需要 7 分钟。

observable

可观察的类countObservers()方法 (Observable Class countObservers() method)

  • countObservers() method is available in java.util package.

    countObservers()方法在java.util包中可用。

  • countObservers() method is used to count the number of observers exists in this Observable.

    countObservers()方法用于计算此Observable中存在的观察者的数量。

  • countObservers() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    countObservers()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名访问该方法,则会收到错误消息。

  • countObservers() method does not throw an exception at the time of counting the observer.

    在计数观察者时, countObservers()方法不会引发异常。

Syntax:

句法:

public int countObservers();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of the method is int, it gets the number of observers in this Observable.

方法的返回类型为int ,它获取此Observable中的观察者数量。

Example:

例:

// Java program to demonstrate the example // of int countObservers() method of Observableimport java.util.*;// Implement Observers class class Observers_1 implements Observer {
public void update(Observable obj, Object ob) {
System.out.println("Obs1: "); }}class Observers_2 implements Observer {
public void update(Observable obj, Object ob) {
System.out.println("Obs2: "); }}// Implement Observed Classclass Observed extends Observable {
// Function call void countObs() {
setChanged(); // By using notifyObservers() method is // to notify all the observers that are // implemented notifyObservers(); }}public class CountObservers {
// Implement Main Method public static void main(String args[]) {
Observed observed = new Observed(); Observers_1 obs1 = new Observers_1(); Observers_2 obs2 = new Observers_2(); observed.addObserver(obs1); observed.addObserver(obs2); // By using countObservers() method is // to return the number of observers // in this object int count_obs = observed.countObservers(); System.out.println("observed.countObservers(): " + count_obs); observed.countObs(); }}

Output

输出量

observed.countObservers(): 2Obs2: Obs1:

翻译自:

observable

转载地址:http://ysxzd.baihongyu.com/

你可能感兴趣的文章
《机器学习实战》学习笔记第二章 —— K-近邻算法
查看>>
uni-app 引入本地iconfont的正确姿势以及阿里图标引入
查看>>
DSB
查看>>
Java中的阻塞队列
查看>>
前端软件sublime的一些常用快捷键
查看>>
openssl 升级
查看>>
2017.10.30 天晴 昨天十公里没减肥
查看>>
Git 打标签(分布式版本控制系统)
查看>>
ASP.NET MVC:通过 FileResult 向 浏览器 发送文件
查看>>
CVE-2010-2883Adobe Reader和Acrobat CoolType.dll栈缓冲区溢出漏洞分析
查看>>
使用正确的姿势跨域
查看>>
AccountManager教程
查看>>
Android学习笔记(十一)——从意图返回结果
查看>>
算法导论笔记(四)算法分析常用符号
查看>>
HttpClient读取数据乱码的解决方案
查看>>
如何使用FireBug插件查询元素的xPath属性
查看>>
ultraedit激活
查看>>
总结(6)--- python基础知识点小结(细全)
查看>>
亿级曝光品牌视频的幕后设定
查看>>
ARPA
查看>>