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 Observable
import 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 Class
class 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(): 2
Obs2:
Obs1:

翻译自: https://www.includehelp.com/java/observable-countobservers-method-with-example.aspx

observable

observable_Java Observable countObservers()方法与示例相关推荐

  1. .net连接mysql数据_.net连接MYSQL数据库的方法及示例!

    连接MYSQL数据库的方法及示例 方法一: 使用MYSQL推出的MySQL Connector/Net is an ADO.NET driver for MySQL 该组件为MYSQL为ADO.NET ...

  2. set.difference() 的用法(python3)_Python 集合 difference_update() 使用方法及示例

    Python 集合 difference_update() 使用方法及示例 Difference_update()使用集合的差集更新集合,并调用difference_update()方法. 如果A和B ...

  3. doc python 颜色_Python wordcloud.ImageColorGenerator方法代码示例

    本文整理汇总了Python中wordcloud.ImageColorGenerator方法的典型用法代码示例.如果您正苦于以下问题:Python wordcloud.ImageColorGenerat ...

  4. isdigit函数在C语言什么意思,C 库函数 isdigit() 使用方法及示例

    C 库函数 isdigit() 使用方法及示例 isdigit()函数检查字符是否为数字字符(0-9). isdigit()的函数原型int isdigit( int arg ); 函数isdigit ...

  5. python中append的用法_Python 列表 append() 使用方法及示例

    Python 列表 append() 使用方法及示例 append()方法将一个项目添加到列表的末尾. append()方法将单个项目添加到列表的末尾. append()方法的语法为:list.app ...

  6. java kryo_Kryo框架使用方法代码示例

    Kryo框架的source已移至https://github.com/EsotericSoftware/kryo ,进入此页面,然后点击右边的Download Zip按钮,就能下载到最新版本的Kryo ...

  7. python文件的用法,Python 文件 readlines() 使用方法及示例

    Python 文件 readlines() 使用方法及示例 概述 readlines() 方法用于读取所有行(直到结束符 EOF)并返回列表,该列表可以由 Python 的 for... in ... ...

  8. php一些单选、复选框的默认选择方法(示例)

    转载 http://www.php.cn/php-weizijiaocheng-360029.html 一. radio和checkbox及php select默认选择的实现代码 1.radio单选框 ...

  9. java math round小数_Java Math round() 使用方法及示例

    Java Math round() 使用方法及示例 Java Math round()方法将指定的值四舍五入为最接近的int或long值,然后将其返回. 也就是说,1.2四舍五入为1,1.8四舍五入为 ...

最新文章

  1. python的类的super()
  2. 基于PHP的图片共享网站设计,基于php实现的web图片共享系统(论文+程序)
  3. 科大星云诗社动态20210318
  4. 读取不同位置的配置文件
  5. 信息学奥赛一本通C++语言——1105:数组逆序重存放
  6. 存储与硬盘挂载 200305
  7. mybatis-generator 详细配置及使用,爬坑记录
  8. thinkPHP 模板中的语法
  9. Java:键盘输入一个小数,输出其整数部分
  10. 详解:MapReduce 思想解析
  11. R语言中rvest包爬虫代码+示例讲解(爬取当当网)
  12. python乌龟吃鱼_关于乌龟吃鱼游戏的问题
  13. vb.net 教程 5-19 拓展:制作一个QQ大家来找茬和美女找茬辅助工具
  14. Mac CAD2018 安装完成后,打开注册机时出现 应用程序“02_注册机”不能打开。
  15. mfc chartctrl 饼状图编写_南瓜糯米饼:外酥里糯,吃到嘴巴里,真是舌尖上的享受...
  16. 关于DE405星历表的调用
  17. 微信支付-扫码支付方式在ThinkPHP商城中的使用(第二部分)
  18. gitweb 搭建教程
  19. 基于OpenSfM的单目三维重建实现详细步骤
  20. 黑群晖6.x安装教程

热门文章

  1. mysql判断数字的函数_Mysql必读MySql判断汉字、日期、数字的具体函数
  2. 微信小程序echarts层级太高
  3. 代码风格之Prettier简介
  4. Maven补全之生命周期(Lifecycle)
  5. Leetcode 565. Array Nesting
  6. NPOI之Excel——设置单元格背景色
  7. ZooKeeper的原理(转)
  8. 142. Linked List Cycle II
  9. class threading.Thread()说明:
  10. 2014-08-26 遇到的小问题