Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Sequence: Access via [n] #219

Closed
CeylonMigrationBot opened this issue Nov 23, 2011 · 3 comments
Closed

Sequence: Access via [n] #219

CeylonMigrationBot opened this issue Nov 23, 2011 · 3 comments

Comments

@CeylonMigrationBot
Copy link

[@alexanderbell] Hi,

I tried to use Sequences with a user defined type:

Emplyee class:

shared class Employee(String pFirstname, String pLastname) 
    extends Person()  satisfies LegalEntity {
    shared String firstname = pFirstname;
    shared String lastname = pLastname;
    shared String fullname = "Employee " lastname ", " firstname "";
    shared actual String info {
        return "Employee Info " firstname "";
    }
}

Now, I wann store some employees in a sequence:

Employee[] employees = { Employee("Alex", "Bell"), Employee("Just", "Me") };

Afterward I pass the sequence to a method. In that method I wanna read the first element for instance:

Employee? employee = employees[0];

Ok, to access the employee I have to do a null check:

Option 1:

    if(exists employee) {
        print(employee.firstname);
    }

Option 2:

    if(is Employee employee) {
        print(employee.firstname);
    }

Unfortuantely it doesn't work. IMO it's a problem of the access method of the sequence.
When I replace Employee? employee = employees[0]; with Employee? employee = employees.item(0); it works fine.

cheers Alex

[Migrated from ceylon/ceylon-compiler#219]
[Closed at 2011-11-23 12:44:39]

@CeylonMigrationBot
Copy link
Author

[@FroMage] Yes this is a case of #72, sorry you have to wait until things stabilise a bit.

@CeylonMigrationBot
Copy link
Author

[@alexanderbell] Ops sorry I was looking for a comparable issue unfortunately I didn't find #72.
I just playing around with Ceylon right now. Probably it's better when I collect my issues and post them on the dev-list first instead of open an git issue, isn't it?

@CeylonMigrationBot
Copy link
Author

[@FroMage] Don't worry, either way is fine :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant