Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 194996

Summary: [encapsulate field] Encap. a field yields comp. error due to override getter
Product: [Eclipse Project] JDT Reporter: kely_garcia <kely_garcia>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: xiemaisi
Version: 3.3   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug

Description kely_garcia CLA 2007-06-30 01:41:38 EDT
Steps To Reproduce:
Build id: I20070608-1718

Encapsulate field "theField" on the following:

public class A {
	String theField;

	public static void main(String[] args) {
		B b = new A().new B();
		System.out.println(b.getTheField());
	}

	class B extends A {
		private String getTheField() {
			return theField;
		}
	}
}

Yields the following refactored code:
public class A {
	private String theField;

	public static void main(String[] args) {
		B b = new A().new B();
		System.out.println(b.getTheField());
	}

	void setTheField(String theField) {
		this.theField = theField;
	}

	String getTheField() {
		return theField;
	}

	class B extends A {
		private String getTheField() {
			return theField;
		}
	}
}

The compilation error is: "cannot reduce the visibility of inherited method from A"

More information:
Comment 1 Olivier Thomann CLA 2007-07-01 18:14:44 EDT
Move to JDT/UI
Comment 2 Martin Aeschlimann CLA 2007-11-12 12:24:37 EST
*** Bug 209317 has been marked as a duplicate of this bug. ***
Comment 3 Eclipse Genie CLA 2019-09-02 08:00:26 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.